Lets say I have two branches A
and B
(A)--------(A+B)--------------(A+B+R)
\\ / merge \\ revert /
\\ /
You need to revert the revert, i.e. revert the commit that your previous revert created.
The reason for this is that a merge really does 2 things: it changes the file contents to reflect the merge, and also creates a commit with 2 parents to tell git what was merged. When you revert, it undoes the first thing, but not the second. So when you try to re-do the merge, git has no idea that you reverted the previous merge, so it ignores everything before then.
Read here how to "reset" your changes How to move HEAD back to a previous location? (Detached head)
Once you have the code you want it push it again to the repository. Since you did a revert and not reset you can simply push the code without any problem.
If you have done a reset
and you wish to update the remote branch you will have to force
push with the git push -f origin master
and this will result in a rebase which will affect all your co workers as well.
How can i get the changes again?
git cherry-pick
The easiest way is simply to do a git cherry-pick
to pick the desired commit back to your branch again.
# Find out the range of commits you wish to re-add to your branch.
# then use cherry-pick to add them back to the branch
git cherry-pick start..end
# If you wish to include the start commit as well add the ^
# This will result in a cherry-pick of the start commit included as well
git cherry-pick start^..end
git rebase --onto
(Carefull = rebase)# reset it to the start commit
git reset --hard start
# rebase every commit after b and transplant it onto a
git rebase --onto commit1 commit2 commit3 ... commitN