jolema
jolema

Reputation: 41

How to undo a git push on the wrong branch

I made changes to several files, committed and pushed them to the master only to realize I was on the wrong branch for the commits and push. How can I undo this? I am not sure if git reset will give me what I want.

Upvotes: 4

Views: 6553

Answers (1)

Jonathan.Brink
Jonathan.Brink

Reputation: 25373

To avoid having to rewrite the history you can use git revert.

This will create a new commit that is the inverse of the commit you accidentally pushed.

Find the sha's of the commits you pushed and run this command for each sha:

git revert <sha>

Then push your revert commits.

Upvotes: 4

Related Questions