Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
17 events
when toggle format what by license comment
Dec 12, 2023 at 8:21 history edited Mauricio Gracia Gutierrez CC BY-SA 4.0
improve the existing answer to make is self contained and updated
Jul 11, 2020 at 10:23 comment added zenoh Remember to provide the full path to file, e.g git checkout -- src/js/filename!!!
Aug 3, 2016 at 12:13 comment added Kristof Pal git checkout <commit-blob> -- /path/to/file/FileName.cc
May 27, 2016 at 2:57 comment added smwikipedia HEAD is just a movable pointer that can point to anywhere. Search the DETACHED HEAD section from here: git-scm.com/docs/git-checkout
May 13, 2016 at 18:23 review Suggested edits
May 13, 2016 at 19:59
Feb 4, 2016 at 12:47 comment added Erick Asto Oblitas @BrianCampbell How can I do the inverse, keep local changes in one file and discard incoming change. I have 'error: Your local changes to the following files would be overwritten by merge:'
May 30, 2014 at 2:30 history edited user456814 CC BY-SA 3.0
Removed horizontal scrolling.
May 13, 2014 at 15:34 comment added Brian Campbell @gwho Yes, you can do HEAD^^ for 2 commits from the most recent, or HEAD^^^ for 3 commits back. You can also use HEAD~2, or HEAD~3, which gets more convenient if you want to go more commits back, while HEAD^2 means "the second parent of this commit"; because of merge commits, a commit can have more than one previous commit, so with HEAD^ a number selects which of those parents, while with HEAD~ a number always selects the first parent but that number of commits back. See git help rev-parse for more details.
May 13, 2014 at 5:20 comment added ahnbizcad Then does that mean you can you do HEAD^^ for 2 commits from the most recent?
Jun 13, 2013 at 21:56 comment added Olie NOTE: If the file is already staged, you need to reset it, first. git reset HEAD <filename> ; git checkout -- <filename>
Feb 15, 2013 at 15:57 comment added Naoise Golden git checkout HEAD^ -- filename to revert to file state before last commit
Mar 2, 2010 at 15:46 comment added lprsd In short "git checkout sha-reference -- filename" where the sha-reference is a reference to the sha of a commit, in any form (branch, tag, parent, etc.)
Mar 29, 2009 at 2:07 history edited Brian Campbell CC BY-SA 2.5
clarify what the different revision identifiers mean
Mar 28, 2009 at 22:21 comment added Paul HEAD is the most recent commit on the current branch, and HEAD^ is the commit before that on the current branch. For the situation you describe, you could use git checkout HEAD -- filename.
Mar 28, 2009 at 22:06 comment added hasen what's the difference between HEAD and HEAD^?
Mar 28, 2009 at 6:46 vote accept hasen
Mar 28, 2009 at 6:12 history answered Brian Campbell CC BY-SA 2.5