Suppose I have a file a.txt. One day, I deleted it, committed, and pushed.
The next day, I wanted like to revert the last commit, bringing back a.txt. I tried using git revert, but when I did git blame, all lines are showing the revert commit hash. The original blame history is lost.
Can I recover the file and preserve the file history, i.e., as if the file has not been deleted before? Note that I must not change the history as the commit has been pushed.
Thanks!
You can do it by using
git resetinstead ofgit revert.git resetdrops the new commit and checkout a previous commit. This is not recommended if you pushed already to upstream.Since you did already push:
git resetand force the pushgit push -f.