1

I know git checkout <sha> -- <filename> will rever the given file to a given version but I want that file to be restored but not overwrite the existing file

elaboration:

  1. suppose i have one file a.txt
  2. i want to create one file b.txt which is just a previous version of a.txt from some other commit

if i can just read that complete version of a.txt somehow .. i can redirect it to b.txt

ashish singh
  • 6,526
  • 2
  • 15
  • 35
  • 1
    Possible duplicate of [git-checkout older revision of a file under a new name](https://stackoverflow.com/questions/888414/git-checkout-older-revision-of-a-file-under-a-new-name) – Raedwald Oct 09 '19 at 13:43

1 Answers1

4
git show <rev>:a.txt > b.txt
# or
git cat-file -p <rev>:a.txt > b.txt

<rev> could be a branch, a tag, a commit, etc. <rev>:a.txt refers to a blob object which stores the content of a.txt of the revision <rev>. git show or git cat-file -p against a blob prints the content, which can be redirected to b.txt.

See gitrevisions.

ElpieKay
  • 27,194
  • 6
  • 32
  • 53