programmer321 programmer321 - 7 months ago 53
Git Question

How does git know which file to checkout when using checkout -- somefile?

I've been practicing

git checkout -- somefile.txt
to checkout git files, in case I mess up. How does Git know which file gets checked out from which commit?

i.e.: I write
git checkout -- index.html
. How does Git know which commit to take index.html from, especially as your commit list gets larger and larger?


git checkout -- some/path is equivalent to git checkout HEAD -- some/path. As with most commands, Git will default to HEAD here which is a reference to the currently checked out branch.

So if you’re on master, then git checkout -- some/path will check out the file from the master branch.