简体   繁体   中英

GIT: How to pull changes from branch after a reverted merge

I hope the title is not very confusing.

History (aka What I did wrong):

Let's say there are two branches, master and feature. Feature is a branch where I keep a longer feature project and from time to time I use git pull origin master on that branch to stay updated with changes in main code.

I accidentally merged and pushed feature into master.

It was nowhere near ready, so I tried to revert it. I tried following: http://sethrobertson.github.io/GitFixUm/fixup.html#pushed_new_merge But I guess I did it wrong. I used: git revert then commited the revert and pushed it. Problem seemed solved - the feature changes where no longer on master.

Now the problem is that when I try to use git pull origin master on feature branch it keeps deleting my files and reverting all changes, as it is merging with the revert-commit. The head of master is way past that revert and I need to pull the changes from newer commits to continue with feature branch.

I've googled the topic and the most promising answer is this: https://metlos.wordpress.com/2012/01/13/git-merging-after-a-revert/ but here the merge goes other way than I want to (feature to master, i need master to feature).

I am thinking of creating clone branch of master, then applying the instructions from the link on that branch so I can get the results I need, but I am afraid it's a temporary solution I would need to apply anytime I want to pull from master.

I tried best for this story not to be chaotic, If something is not understandable I will clarify.

If you have not pushed master branch to a team/public repository and you have no commit after the pull on master, you may do

git reset --hard **the-commit-before-pulling-feature-branch**

on the master branch. This will effectively wipe out the mistake from history and gives a clean history.

otherwise, (ie if you have already pushed master to a repo or done more commits on master), you may do

git revert **the-revert-commit**

on the feature branch after pulling the master, effectively reverting the revert commit.

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