2

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

Community
  • 1
  • 1
q0987
  • 34,938
  • 69
  • 242
  • 387

1 Answers1

2

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).

Community
  • 1
  • 1
torek
  • 448,244
  • 59
  • 642
  • 775
  • I did some experiments. It seems to me that `git checkout -- ' causes no changes if `working copy` is equal to `index`. So I think it is always true that we can use `get checkout HEAD -- path` if you want to get the latest copy from last committed checkin. – q0987 Jan 15 '16 at 15:23