Reputation:
I have done something really weird. And I don't know what to do know.
I am working with Gerrit, and it just showed me that it cannot merge because of a conflict, but there were no conflicts, but instead I guess it was because of detached HEAD
And I started to do really random thing, firstly I cherry-picked
3 commits into one, and than I got the master branch again detached, that I tried to rebase, but got a merge conflict, so finally I got the following log
https://i.sstatic.net/6N6Tt.jpg
This is because I don't understand the difference between merge
and rebase
Could you please help me to fix the history (into one straight line) and answer the question :
What is the difference between merge
and rebase
if by default git uses fast-forward
so the result looks exactly the same as rebase does. And in my case I couldn't make the rebase because of merge conflicts. So what is the purpose of rebase
than ?
Upvotes: 2
Views: 2946
Reputation: 1857
Rebase is different from merge because git uses fast-forward
only if it can. E.g.: you create a new branch from master
, you commit to your new branch, you don't commit to master
, and then you want to merge
your changes back to master: git will think this is the same as if you'd have just committed to master
anyway. And it'll think the same if you'd use rebase
in this situation.
The real fun begins when you have changes on both branches and git can't use fast-forward: then merge
will create a new commit for which the parents will be your last commits on both of your branches, and rebase
will try to move the base of your branch that you're trying to rebase to the head of your other branch.
So, to "fix" your history (into one straight line), you need to undo your merge (labeled as head) and you need to rebase your Rebasing
branch to your master
branch
git checkout Rebasing
git rebase master
You'll still have conflicts, that you need to resolve and continue with
git rebase --continue
as many times as necessary.
Upvotes: 1