问题描述:

Based on Meaning of Git checkout double dashes

git checkout -- fileA.cpp

I want to revert changes on fileA.cpp.

Question> Is there a different between the checkout with or without HEAD?

Thank you

网友答案:

There is a difference, which matters if and only if the version of fileA.cpp in the index differs from the version of fileA.cpp in the HEAD commit.

Specifically, without the word HEAD, git checkout -- <path> extracts the version of <path> from the index to the work-tree, leaving the index version unchanged. Adding HEAD before the --, git checkout HEAD -- <path> extracts the version of <path> from the commit identified by HEAD, writes that into the index, and only then writes the index version (now the same as the HEAD version) into the work-tree.

See also this StackOverflow answer (on git reset initially, but extended to cover checkout as well).

相关阅读:
Top