How to undo a git rm after commit

Issue

I have a file name file.txt.

I have made some changes in the file.txt.

I commit and push these changes.

But now I realize that I don’t need any change in the file in the current branch. So mistakenly I have done git rm file.txt. And then commit and pushed these deletion changes. But it is showing removed this file on my branch.

All I want is that I don’t want to see any change in the file.txt in my branch.

Could anyone please help me here? I have searched on StackOverflow a lot. There are many answers but could not find my case.

Solution

So finally, I got the answers that I want. Here is the steps that I followed.

git checkout deletion_commit_id^ -- file.txt

This will reverted the deletion and then add, commit and push.

After that, I have done undoing of all the changes of this file.

git checkout origin/master file.txt.

And then add, commit and push.

Answered By – starboy_jb

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published