Putting the current branch ahead of master after git revert

476 views Asked by At

I've made a few mistakes in updating my repository, starting with pushing a commit to the master instead of the feature branch.

What I've done to try and fix this is created a new feature branch off the updated master, followed by a git revert on the master.

After committing and pushing the changes master is now ahead of the feature branch by 1 commit I'd like it to be the other way around.

Is it possible to make this change?

1

There are 1 answers

2
Jonathan.Brink On BEST ANSWER

Since you have already pushed the revert commit, you can simply revert-the-revert commit on your feature branch to get those changes back.

So, try this:

git checkout feature
git merge master # get back in sync with master
git revert master # revert-the-revert

For cleaner history, if you haven't pushed the feature branch yet, try this which will avoid the extra merge commit:

git checkout feature
git reset --hard origin/master
git revert master # revert-the-revert

After performing either of those two command sequences your feature branch will now be ahead of master.