1

To hard reset a single file we do something like:

git checkout HEAD -- my-file.txt

or,

git restore my-file.txt

what if we want to restore the file to a different location or with a different name.

i mean i do not want to change my current my-file.txt but want to restore the previous copy of that file as my-file-old.txt.

How can I do that?

Ahmad Ismail
  • 8,816
  • 4
  • 37
  • 60
  • I don't use it much, but I think git stash is meant to keep your current changes somewhere to maybe use later. https://stackoverflow.com/tags/git-stash/info – Marc K Oct 27 '20 at 22:56

1 Answers1

3

Use git show:

git show commit_id:path/to/file > another_path/to/new_name

Example for your case:

git show HEAD:my-file.txt > /tmp/restored-file.txt
phd
  • 69,888
  • 11
  • 97
  • 133