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] #2: two developers work on the same branch simultaneously (same file, diff lines) #2

Open dorawyy opened 7 years ago

dorawyy commented 7 years ago

Cloned the repo twice and commit in each repo to simulate two developers working on the same branch

Scenario abstraction

git_pull_no_conflict

Results:

Data could be explored:

Detailed steps

step0: start point of the test case:

screen shot 2017-10-12 at 11 58 18 pm screen shot 2017-10-13 at 12 06 02 am

Step1: cloned two repos ( already did in testcase #1 )

git clone https://github.com/dorawyy/git-merge-conflicts-test.git git-merge-conflicts-test-1
git clone https://github.com/dorawyy/git-merge-conflicts-test.git git-merge-conflicts-test-2

To make it short, we call them:

Step2: developer1 committed in repo1, TestA branch (SHA``)

git add --testcase2
git commit -m "TestA: developer1 edited line2 of file"

and git log of the file testcase2 after commits

screen shot 2017-10-13 at 12 08 52 am

Step3: developer2 committed in repo2, TestA branch (SHA``)

git add --all
git commit -m "TestA: developer2 edited line8 of file testcase2"
screen shot 2017-10-13 at 12 11 46 am

Step4: developer1 pushed commit on repo1 back to remote repo

# make sure on TestA branch
git branch 
# push change back to remote
git push origin TestA
screen shot 2017-10-13 at 12 12 59 am

When logging back to remote repo(on github), we can see the commit pushed by developer1 just now:

screen shot 2017-10-13 at 12 14 44 am

Step5: developer2 tried pushing commits from repo2 back to remote repo (without pulling first)

# make sure on TestA branch
git branch
# push change back
git push origin TestA

It turned out pushing failed, git required us to pull first. The tree of repo2 has not changed till now.

screen shot 2017-10-13 at 12 15 16 am

Step6: developer2 git pull from repo2 TestA branch

Therefore, we git pull first to get all changes locally

git branch
git pull origin TestA 
screen shot 2017-10-13 at 12 17 52 am

As developer1 and developer2 committed on different lines of the same file, no conflict raised. However, it is still three-way merging, with an extra merge commit.. As the screenshot above shows, when git pull, create a merge commit.

Step7: developer2 pushed commit from repo2 to the remote repo.

git push origin TestA
screen shot 2017-10-13 at 12 22 11 am

Now, we can see commits from github side

screen shot 2017-10-13 at 12 23 35 am

Step9: developer1 git pull, check git tree and git log

git pull origin TestA
git tree 
git log
screen shot 2017-10-13 at 12 24 19 am

The git tree and git log look like: (exactly the same as repo2)

screen shot 2017-10-13 at 12 24 35 am screen shot 2017-10-13 at 12 24 56 am

Data explored here, the merge commit will list the two parent commits as the picture above shows