programmer321 programmer321 - 1 year ago 117
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download