Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 6
    simplest solution and this is what git-checkout is designed for - specifying the pathname means only the matching file is checked out. From git-checkout man page: git checkout master~2 Makefile Commented Mar 28, 2013 at 14:37
  • 1
    Then, how do you go back to the previous state before you run this command? Commented Oct 9, 2013 at 0:50
  • @Flint if you are coming from the HEAD state it would be as simple as git checkout HEAD -- [full path]. Commented Nov 7, 2013 at 17:29
  • 84
    Note that this overwrites the existing file in that path, whereas the git show SHA1:PATH solution only prints to stdout. Commented Jan 22, 2014 at 15:24
  • Nice! I wouldn't have been able to figure this out by looking at git help checkout. I had to checkout a subdirectory as of a certain date, and using this approach, I could get this syntax working: git checkout @{YYYY-MM-DD} sub-dir Commented Jan 25, 2018 at 15:32