dorawyy / git-merge-conflicts-test

This repo is for testing of git functionalities / different merging conflict scenarios, and CI tools usage
2 stars 4 forks source link

[testcase notes] (need to work on) #19: rollback after rebasing #25

Open dorawyy opened 7 years ago

dorawyy commented 7 years ago

Feature3 branch was derived from Feature2, also git rebase was done in #17 . Based on this, test case 18 is going to test rolling back after rebasing

Scenario abstract

1111

Results:

Data could be explored:

Detailed steps:

Step0: prep

git checkout Feature2
touch test17

# edit test17

git add test17
git commit -m "testcase17: startpoint (create file test17)"
screen shot 2017-10-16 at 9 27 21 am screen shot 2017-10-16 at 9 27 54 am

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

git status

<img width="622" alt="screen shot 2017-10-16 at 9 44 09 am" src="https://user-images.githubusercontent.com/16771854/31624159-964fc0bc-b256-11e7-8e71-0666ff888f79.png">

now not in any branch, in a detached rebase status

git branch

<img width="599" alt="screen shot 2017-10-16 at 9 44 44 am" src="https://user-images.githubusercontent.com/16771854/31624182-af59715c-b256-11e7-9ef3-c787057e6032.png">

head is at:

git show --oneline head

<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:

resolve conflict

git add test17

check status

git status

<img width="578" alt="screen shot 2017-10-16 at 9 55 04 am" src="https://user-images.githubusercontent.com/16771854/31624602-1ae80784-b258-11e7-914b-19413d66c8dc.png">

continue rebasing

git rebase --continue

<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="735" alt="screen shot 2017-10-16 at 10 01 22 am" src="https://user-images.githubusercontent.com/16771854/31624876-fce00de4-b258-11e7-9acc-ef0b3e3b9a2d.png">

project status

git status

<img width="613" alt="screen shot 2017-10-16 at 10 01 56 am" src="https://user-images.githubusercontent.com/16771854/31624908-12c798d4-b259-11e7-9d2e-bca1715fa6d7.png">

check branch

git branch

<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">

mark conflict2 resolved

git add test17

check current status

git status

<img width="620" alt="screen shot 2017-10-16 at 10 11 16 am" src="https://user-images.githubusercontent.com/16771854/31625294-6645e154-b25a-11e7-9180-34a145e934d1.png">

continue rebasing

git rebase --continue

check status again

git status

<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:

git checkout Feature2 git branch git log git reflog

<img width="613" alt="screen shot 2017-10-16 at 10 21 33 am" src="https://user-images.githubusercontent.com/16771854/31625700-d5ff19c4-b25b-11e7-8b6a-1e19414ba0f7.png">
<img width="547" alt="screen shot 2017-10-16 at 10 22 35 am" src="https://user-images.githubusercontent.com/16771854/31625728-f522492a-b25b-11e7-9f47-eb0fd7e5de31.png">

* `Feature3` branch:

git checkout Feature3 git branch git log git reflog


<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`