简体   繁体   中英

Putting the current branch ahead of master after git revert

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM