开发者

How to undelete a file previously deleted in git's history?

开发者 https://www.devze.com 2023-01-05 01:54 出处:网络
Using Chris\'s answer on another question I could prepend a snapshot-history to my git repository. Since one of the files is not part of my history but only in th开发者_运维百科e snapshots, the first

Using Chris's answer on another question I could prepend a snapshot-history to my git repository. Since one of the files is not part of my history but only in th开发者_运维百科e snapshots, the first original commit now also contains the deletion of this file. How can I undo that?

At first I thought this was the opposite of How do I remove sensitive files from git’s history, but actually I don't want to insert a file into history but just remove the deletion from history.


git checkout <commit> <filename>


I got it:

git tag originalHead # just in case
git rebase -i <id of the parent of the commit that deleted the file>
# change pick to edit for that commit
git checkout <id of the previous commit> <filename> # thanks for reminding, kubi
git commit --amend
git rebase --continue
git tag -d originalHead

edit unfortunately this will leave all tags at the old timeline, see here

0

精彩评论

暂无评论...
验证码 换一张
取 消