I am fairly new to git and I made a mess.
I had two branches - release and develop branch.
My release branch was 100 commits behind and 10 commits ahead of the develop branch.
I wanted the 10 commits ahead in the release branch to be committed to the develop branch so I created a pull request from release branch to develop branch but there were some merge conflicts so I used the following commands that I found to resolve the merge conflict:
git checkout release
git pull --rebase origin develop
If there are some conflicts, go to these files to modify them.
git add #your_changes_files
git pull
git push origin release
Unfortunately after I merged the pull request, I observed that my release branch was in sync with my develop branch i.e. the 100 commits behind which were a part of the develop branch also became a part of the release branch. I want my release branch to go back to the state it was before the merge(100 commits behind and 10 commits ahead).
Please help me fix this.
Thanks in advance.
CodePudding user response:
To bring back your release branch to the previous state, use the following command
git revert -m 2 <merge_id>
git push origin <release-branch>
CodePudding user response:
From the beginning you had to rebase your develop branch over the release branch
git checkout develop
git rebase release
This will make your develop branch to be 100 commits ahead and 0 commits behind release branch.
So now you have to
git reset --hard HEAD~1
on both branches than execute command mentioned above
CodePudding user response:
To go back to your previous state, you can do:
git checkout release
git reset --hard release@{2.hours.ago}
That puts the branch at a state where it was two hours ago. Choose a reasonable time span that points between when you did the last commit on the branch and when you did the pull --rebase.
You can also investigate the reflog and choose the commit that is before the git pull --rebase was completed:
git reflog show release
git reset --hard release@{2} # for example
Verify that you are at the right commit:
git log --pretty=fuller # observe the commit date; should be before you did the pull --rebase
Then push out the corrected branch.
