When will git rebase have conflict?

Viewed 82

I have been reading several posts on this forum, progit, Youtube and some random blogs for rebase.

The most general form to conclude this subject is:

- A - B - C   Master
   \  D - E Topic

and I perform:

git checkout Topic
git rebase Master

Ideally, it would be:

- A - B - C - D' - E' Master, Topic

But the 2 concerns are:

  1. Is D' = D, E' = E?
  2. What is git rebase conflict?

Regarding to the first concern and this post,

  1. Rebase do merging on D and E, and above all, with complicated input.

For example, when it goes to D, according to the post and if I am correct

  1. HEAD detached to C
  2. Git compares between changes from A to D and changes from A to C
  3. After merging, git compares between D', D and E

And this confuses me the most. Why does merge involving more than 2 commits? Also, how does a conflict appear?

EDIT:

Ran some commands, please see the following:

git init

Created a Random.txt Content: Master 1

git add Random.txt
git commit -m "Master 1"

Create new branch

git checkout -b rebase_conflict

Alter Random.txt Content: 1

git add Random.txt
git commit -m "Conflict 1"

Alter Random. txt Content: 2

git add Random.txt
git commit -m "Conflict 1"

Switch to master

git checkout master

Alter Random.txt content: Master 2

git add Random.txt
git commit -m "Master 2"

Switch branch and rebase

git checkout rebase_conflict
git rebase master

Get conflict error Alter Random.txt Content: 1

git add Random.txt
git rebase --continue

At this point, I expect another rebase conflict, because according to the logic

-- Master 1 -- Master 2
  \ -- Conflict 1 -- Conflict 2

After first rebase

-- Master 1 -- Master 2 -- Conflict 1'
 \ -- Conflict 1 -- Conflict 2

At this stage I am expecting a new commit on top of Conflict 1'. Isn't there a merge conflict between Conflict 2 and Conflict 1'?

Because Conflict 1' Random.txt content: 1, whereas

Conflict 2 Random.txt content: 2

They change the same line, isn't it?

1 Answers

Either merging or rebasing in your above example can result in merge conflicts. It is possible that only one or the other would have conflicts too. To understand what rebasing does, consider the following diagram which shows what Topic would look like after rebasing on Master:

Topic:  -- A -- B -- C -- D' -- E'

Here the apostrophes indicate that the D and E commits have been reapplied onto the new base of Master. As each commit is reapplied, there exists the chance for merge conflicts. So, in the case of reapplying N commits, there could be N sets of merge conflicts. On the other hand, a merge would always result in at most one set of merge conflicts. If this be a concern of yours, then you might favor merging over rebasing.

Related