How to re-commit a past commit if someone overwritten my commit

  • A+

Just faced an issue where someone overwritten my whole commit and there are lot of other commits on top of this, now I have to re-commit that particular commit. Any help would be appreciated.

Someone got merge conflict and while merging he lost my all changes. I don't know what he did, but my changes are not there. IN history my commit is there but If I am seeing above his merge my changes are reverted.

Now I cannot revert his merge commit because it contains lots of files as compare to me also I don't want to change each file one by one manually. Is there any way to get back my changes without effecting other's.


You can do that typing the following commands:

$ git reflog 

then select the ID of the commit that you want to retrieve.

Then type the following command:

$ git cherry-pick <'ID'> 

Instead of <'ID'> enter the ID from the above reflog.

Then you will have the changes of that commit.

Now check if anything is still remaining by:

$ git status 

If anything is in unstaged commit, then add it by the following commands and commit:

$ git add -A //Any other option or the name of the file with the path that you want to commit $ git commit -m "Your message here for that commit" $ git push 

I hope this answer is what you are expecting for.


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: