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.
Using git reset to Undo a Merge This means that any local changes in your Working Copy will be discarded; if you have valuable uncommitted changes, be sure to use git stash before.
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, (i.e. 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With