2

In git, we can use git show commitlike:filepath to show a file as it was at a particular revision, and using shell redirection we can retrieve that version and put it back in the working tree somewhere: git show commitlike:filepath > otherpath.

Is there a single git command to perform the latter task? git checkout commitlike -- filename can retrieve the file but only put it in its original location.

Kara Brightwell
  • 2,529
  • 1
  • 21
  • 29
  • 5
    There might be some clever way to do it with the plumbing commands, but `git show` and redirection seems like the most sensible. – cmbuckley Jun 25 '14 at 11:12
  • possible duplicate of [Is there a quick git command to see an old version of a file?](http://stackoverflow.com/questions/338436/is-there-a-quick-git-command-to-see-an-old-version-of-a-file) – Dahir Warsame Jun 25 '14 at 13:23
  • Not a duplicate, I want to put the file back in the working tree not display its contents. – Kara Brightwell Jun 26 '14 at 09:43

1 Answers1

0
$ git config --global alias.getfile '!sh -c '"'"'git show $1:$2 > $3'"'"' -'

Then you can do this:

$ git getfile COMMITLIKE FILE_PATH DESTINATION_FILE

For example:

$ git getfile HEAD~3 .gitignore old_gitignore
Cyrille Pontvieux
  • 2,356
  • 1
  • 21
  • 29