create two new commits on Feature2 branch
For example, re-edit test file test17 line 12 twice
git checkout Feature2
edit test17, line 12
git add test17
git commit -m "Feature2: edit1 the file test17, line 12"
<img width="811" alt="screen shot 2017-10-16 at 9 33 59 am" src="https://user-images.githubusercontent.com/16771854/31623698-2aa7a88a-b255-11e7-804c-1954afd2bd37.png">
<img width="763" alt="screen shot 2017-10-16 at 9 33 13 am" src="https://user-images.githubusercontent.com/16771854/31623672-1104f1a8-b255-11e7-9ae8-5bf1d738cde6.png">
Here is the second edit:
git checkout Feature2
edit test17, line 12
git add test17
git commit -m "Feature2: edit2 the file test17, line 12"
<img width="800" alt="screen shot 2017-10-16 at 9 35 28 am" src="https://user-images.githubusercontent.com/16771854/31623766-5f261326-b255-11e7-83a4-a98b37eb7b46.png">
<img width="761" alt="screen shot 2017-10-16 at 9 34 47 am" src="https://user-images.githubusercontent.com/16771854/31623748-4dcc7958-b255-11e7-8d48-d55f4f9bc794.png">
* create two new commits on `Feature3` branch
For example, edit test file `test17` **twice**
git checkout Feature3
edit test17, line 12
git add test17
git commit -m "Feature3: edit1 the file test17, line 12"
<img width="761" alt="screen shot 2017-10-16 at 9 36 15 am" src="https://user-images.githubusercontent.com/16771854/31623807-7c307dee-b255-11e7-8ef5-4b94416ee2f7.png">
<img width="811" alt="screen shot 2017-10-16 at 9 36 42 am" src="https://user-images.githubusercontent.com/16771854/31623827-89f173d4-b255-11e7-8f4e-46e023d91b10.png">
Here is the second edit:
git checkout Feature3
edit test17, line 12
git add test17
git commit -m "Feature3: edit2 the file test17, line 12"
<img width="762" alt="screen shot 2017-10-16 at 9 37 13 am" src="https://user-images.githubusercontent.com/16771854/31623839-9db33718-b255-11e7-8132-bc5dad4b54d8.png">
<img width="792" alt="screen shot 2017-10-16 at 9 37 38 am" src="https://user-images.githubusercontent.com/16771854/31623855-abd85f12-b255-11e7-8c89-1d3587c0bc1e.png">
Now, preparation work is done, and the project log becomes (diverge appears):
<img width="645" alt="screen shot 2017-10-16 at 9 37 57 am" src="https://user-images.githubusercontent.com/16771854/31623871-baf2e594-b255-11e7-85d1-fde75f96756d.png">
![wechatimg275](https://user-images.githubusercontent.com/16771854/31624296-14684a14-b257-11e7-903b-bc368a77bcf3.jpeg)
### Step1: Rebase `Feature3` branch
git checkout Feature3
git rebase Feature2
Merge conflict raised here. Looking into the file ` /Users/dora/git-merge-conflicts-test-1/.git/rebase-apply/patch`, the content is:
<img width="710" alt="screen shot 2017-10-16 at 9 41 07 am" src="https://user-images.githubusercontent.com/16771854/31624042-38b050f2-b256-11e7-81a0-8cb483973b2f.png">
Check current working directory and index
As can be seen, now in process to rebase branch Feature3 on the latest commit of Feature2 branch
<img width="685" alt="screen shot 2017-10-16 at 9 45 33 am" src="https://user-images.githubusercontent.com/16771854/31624220-c7ca00d0-b256-11e7-9a34-6274c9cd1682.png">
In next step, we need to resolve the conflict.
### Step2: Resolve rebase conflict
Current project status:
<img width="496" alt="screen shot 2017-10-16 at 9 54 14 am" src="https://user-images.githubusercontent.com/16771854/31624564-fc7c4076-b257-11e7-98cb-3d3e5a3257bd.png">
As we can see from last step, the conflict is `content conflict` in the file `test17`. Current `test17` is:
( checking out `Feature3` branch)
<img width="755" alt="screen shot 2017-10-16 at 9 52 05 am" src="https://user-images.githubusercontent.com/16771854/31624480-b390960a-b257-11e7-8f15-6aabb4719f8a.png">
Modify `test17` to:
<img width="758" alt="screen shot 2017-10-16 at 9 53 25 am" src="https://user-images.githubusercontent.com/16771854/31624520-dfe975a0-b257-11e7-9aaa-8ff66b4a1b48.png">
Then, mark the rebase conflict resolved and continue rebase:
<img width="683" alt="screen shot 2017-10-16 at 9 58 43 am" src="https://user-images.githubusercontent.com/16771854/31624767-9e1b424c-b258-11e7-8c12-9b6f93c740a7.png">
The project history becomes (the Feature3 edit1 commit is already applied on tip of Feature2):
<img width="1005" alt="screen shot 2017-10-16 at 10 05 15 am" src="https://user-images.githubusercontent.com/16771854/31625070-9769be50-b259-11e7-8c5c-85113b285067.png">
However, a new conflict raised - when continue rebasing. As we can see from the log here,
* Feature3 edit1 commit is already applied (after resolving the rebase conflict);
* Feature3 edit2 commit now raise a rebase conflict --> need to resolve.
In the next step, the developer is going to resolve the second conflict.
### Step3: Resolve the second rebase conflict
First, get more details about the second conflict.
look into the patch file
vim /Users/dora/git-merge-conflicts-test-1/.git/rebase-apply/patch
<img width="574" alt="screen shot 2017-10-16 at 10 02 17 am" src="https://user-images.githubusercontent.com/16771854/31624918-1cbe65f2-b259-11e7-8afe-4de64ee0ba19.png">
The conflict file is `test17`, current version is:
( conflict between the newly-applied Feature3 edit1 commit on tip of Feature2, and `HEAD` of Feature2 branch, which is Feature2 edit1 commit)
<img width="761" alt="screen shot 2017-10-16 at 10 03 28 am" src="https://user-images.githubusercontent.com/16771854/31624974-49c928d4-b259-11e7-82b6-9bb13d13ef9d.png">
Now, resolve the conflict:
<img width="764" alt="screen shot 2017-10-16 at 10 09 59 am" src="https://user-images.githubusercontent.com/16771854/31625240-31818752-b25a-11e7-832b-10eab8eac8d5.png">
<img width="567" alt="screen shot 2017-10-16 at 10 12 16 am" src="https://user-images.githubusercontent.com/16771854/31625322-81d1bbd2-b25a-11e7-987d-e4b2e3454788.png">
Now the rebase process is done, and the project history becomes:
<img width="1002" alt="screen shot 2017-10-16 at 10 12 52 am" src="https://user-images.githubusercontent.com/16771854/31625348-97f8db5c-b25a-11e7-9c10-5278714a1a44.png">
The previous two commits of Feature3 branch now is rebased to the head of Feature2 branch. ( SHA changed, the old Feature3 commits are not visible in log anymore)
Here is the comparison scratch:
![wechatimg276](https://user-images.githubusercontent.com/16771854/31625604-76f44ed6-b25b-11e7-93b1-a02484498805.jpeg)
### Step4: Merge Feature2 branch forward
git checkout Feature2
git merge Feature3
<img width="635" alt="screen shot 2017-10-16 at 10 20 38 am" src="https://user-images.githubusercontent.com/16771854/31625662-b0fc8c56-b25b-11e7-8e28-719280408e40.png">
### Step5: Check `git log` and `git reflog` to explore data
* `Feature2` branch:
<img width="535" alt="screen shot 2017-10-16 at 10 23 39 am" src="https://user-images.githubusercontent.com/16771854/31625759-1c837e62-b25c-11e7-9113-d4e2eae7134a.png">
<img width="562" alt="screen shot 2017-10-16 at 10 24 16 am" src="https://user-images.githubusercontent.com/16771854/31625784-310795c6-b25c-11e7-8b2b-9f703ae8c1af.png">
**As we can see,**
* the `rebase` is applied one by one on the tip of the base branch
* no extra visible commit is noted down for `rebasing`
* no record in `git log`
* only visible in `git reflog`
* no record for `rebase conflict`
* no record in `git log`
* no record in `git reflog` about conflicts
* fast-forward merging, thus no merge commit is created
* no record in `git log`
* only visible in `git reflog`
Feature3 branch was derived from Feature2, also
git rebase
was done in #17 . Based on this, test case 18 is going to testrolling back
after rebasingScenario abstract
Feature2
andFeature3
),Feature3
was derived fromFeature2
;Feature3
branch was created,Feature3
made several commit ( for example, all edit lineX of fileY)Feature2
edit line X of fileY, 1 commitFeature3
back toFeature2
Feature3
branch --git rebase Feature2
Results:
rebasing
, andgit log
is modified directly.Data could be explored:
git log
git reflog
git log
git reflog
Detailed steps:
Step0: prep
test15
onFeature2
branchsync
Feature2
andFeature3
create two new commits on
Feature2
branch For example, re-edit test filetest17
line 12 twiceedit test17, line 12
git add test17 git commit -m "Feature2: edit1 the file test17, line 12"
git checkout Feature2
edit test17, line 12
git add test17 git commit -m "Feature2: edit2 the file test17, line 12"
git checkout Feature3
edit test17, line 12
git add test17 git commit -m "Feature3: edit1 the file test17, line 12"
git checkout Feature3
edit test17, line 12
git add test17 git commit -m "Feature3: edit2 the file test17, line 12"
git checkout Feature3 git rebase Feature2
As can be seen, now in process to rebase branch Feature3 on the latest commit of Feature2 branch
git status
now not in any branch, in a detached rebase status
git branch
head is at:
git show --oneline head
resolve conflict
git add test17
check status
git status
continue rebasing
git rebase --continue
look into the patch file
vim /Users/dora/git-merge-conflicts-test-1/.git/rebase-apply/patch
project status
git status
check branch
git branch
mark conflict2 resolved
git add test17
check current status
git status
continue rebasing
git rebase --continue
check status again
git status
git checkout Feature2 git merge Feature3
git checkout Feature2 git branch git log git reflog
git checkout Feature3 git branch git log git reflog