19

I am new to git. I wanted to push my data to my branch but instead I pushed it upstream/master branch. I want revert that push. Is there any way?

Any help is appreciated.

user1079065
  • 2,085
  • 9
  • 30
  • 53

3 Answers3

35

Revert locally and push your revert

git revert <commit_id>
git push upstream/master

This is better than deleting your history if you're collaborating with a team on the upstream repo. If you do hard reset and force push, you could end up removing other commits by other people. It's better to just roll back your changes and show that in the team history.

yelsayed
  • 5,236
  • 3
  • 27
  • 38
19
git checkout -b myfeaturebranch
git checkout master
git reset --hard HEAD~1
git push --force

This does the following:

  1. Creates a new local branch with the commits you made
  2. Goes back to the master branch
  3. Resets the commit pointer back one commit
  4. Pushes the reset which removes the commit from the remote

The danger here is if anyone else pulled from master those commits will be lost. In that case, you'll want to use revert instead of reset which will record the reset as part of the commit history.

git checkout -b myfeaturebranch
git checkout master
git revert HEAD~1
git push
Jordan Parmer
  • 36,042
  • 30
  • 97
  • 119
0

I face this same scenario for me !

  1. git revert
  2. unstaged the selected files from source tree or other
  3. git reset --soft HEAD~1

This makes reset the master changes into Tree in you tools.

Ajay
  • 1
  • 1
  • 2