Background
In the repository I'm working on,
There's a main branch master
and a protected development branch stage
.
We developers send all our MRs to stage
and the admin updates master
with stage
when its the right time.
What I did
So I was on my branch, let's call it changesA
. I have been working on it since 2 days, during which the stage branch had been updated after merging some branches.
Today, after updating my remote branch with my changes, I take a pull from stage -
git pull origin stage
There were a few merge conflicts, let's say in 10 files. I resolved them and pushed the changes. So now my remote branch is updated with stage. A new merge commit was created in my commit history with 152 changed files (1587 additions and 4543 deletions).
I realised that I made some mistakes while resolving those conflicts. So I reverted my merge commit using this method. A new revert commit was added to my commit history with 152 changed files (4543 additions and 1587 deletions).
I worked more on my branch and updated my remote branch with the changes.
What's the problem
At this point, I expect my branch to be behind stage since I reverted my pull. And I expect there to be conflicts in those 10 files that I basically unresolved when I reverted the merge commit.
But when I run the same command git pull origin stage
, it says that my branch is already up to date with stage. I believe for some reason, my branch has been marked as resolved and updated with stage.
What went wrong here and how can I resolve those same 10 conflicts?
What I've tried (that didn't work)
- I tried checked out to stage and updated my local stage.
git fetch
on my branch.- I created a copy of my branch by
git checkout -b changesACopy
and triedgit pull origin stage
. Got the same message. - I deleted all my local branches, checked out stage and took a pull. Then checked out my branch and took a pull.
- I checked out a branch from stage and created a change to one file that will create a merge conflict with my branch. Merged that branch to stage. I expect there to be 11 files with merge conflicts with my branch, but there was just one.
What worked
Well there are no shortcuts. Here are the steps that I took to resolve this -
git reset --hard HEAD~4
to the point where I pushed my changes just before pulling from stage.git pull origin stage
again. This time I get to resolve those 10 conflicts again. (I did it right this time!)git cherry-pick <commit-hash>
of my latest changes that I pushed after reverting.git push origin changesA --force
. Force was needed because I went back in history, so my local branch is behind my remote and git would reject any push before pulling. I was working on my branch alone so I knew that I won't be overwriting any changes if I force push.
DONE!
Thanks for all the help. I knew this course of action but I wished to know why revert didn't work like I expected it to. The accepted answer covers that.