Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to undelete file in git and keep his original blame history ?

Tags:

git

I'v accidentally removed a file (I wasn't his creator) and commit and push it to the remote. Now I want to make git to undelete this change but when I use git revert #mistaken commit it works BUT blame information points at me as the creator of this file not for his original creator. Can anyone knows how to undelete this file in git and keep its original blame history ? Thanks in advance for any help. Adam

like image 789
Adamos Avatar asked Oct 16 '25 20:10

Adamos


1 Answers

The only way to do what you want is to rewrite the revision history with something like Find and restore a deleted file in a Git repository. However, this has the nasty side-effect that everyone who has made commits since the file was deleted will now need to rebase their code. As you can imagine, this will cause a lot of work for everyone on the team.

For the sake of everyone's sanity, it is best just to revert the single commit and leave the "blame" as your own. A little bit of history archaeology will show anyone interested what happened.

like image 190
Code-Apprentice Avatar answered Oct 19 '25 13:10

Code-Apprentice



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!