Git revert deleted file and preserve file history -


suppose have file a.txt. 1 day, deleted it, committed, , pushed.

the next day, wanted revert last commit, bringing a.txt. tried using git revert, when did git blame, lines showing revert commit hash. original blame history lost.

can recover file , preserve file history, i.e., if file has not been deleted before? note must not change history commit has been pushed.

thanks!

you can this! here's how:

  1. start new branch commit preceding delete want undo.
  2. merge offending change git merge <sha> -s ours.
  3. if commit had changes besides deletion want keep:
    1. reapply changes working copy git diff <sha>^..<sha> | git apply.
    2. discard deletions (many techniques available; git checkout -p may work you).
  4. merge branch main branch (e.g. master).

this produces history 2 branches; 1 in file deleted, , 1 in it never deleted. result, git able track file history without resorting heroics such -c -c -c. (in fact, -c -c -c, file isn't "restored", because git sees new file created as copy of existing file. technique, reintroducing the same file repository.)


Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -

java - How can I send the data from a imput type="file" to the controller? -