git pull scenarios

Scenario 1  (both users U1 and U2 are in sync; U2 modified committed and pushed file B; U1 executes git pull –> fast forward merge updates file B, not merge commit happens):

  • U1: create file A and B commits it and pushes to repo
  • U2: pull changes
  • U2: modifies only B, commits and pushes
  • U1: pull #no conflicts, automatically U2 fast-forward commit in incorporated for U1, no merge commit
#u1
git clone https://github.com/bmwieczorek/git-pull-merge.git git-pull-merge-u1
cd git-pull-merge-u1
echo "u1 created a.txt" > a.txt
git add a.txt
git commit -m "u1 created a.txt"
echo "u1 created b.txt" > b.txt
git add b.txt
git commit -m "u1 created b.txt"
git push origin master
cd ..
#u2
git clone https://github.com/bmwieczorek/git-pull-merge.git git-pull-merge-u2
cd git-pull-merge-u2
echo "u2 append 1x b.txt" >> b.txt
git add b.txt
git commit -am "u2 append 1x b.txt"
git push origin master
cd ..
#u1
cd git-pull-merge-u1
git pull
$ git pull
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/bmwieczorek/git-pull-merge
 7dde4b0..6b1b5a1 master -> origin/master
Updating 7dde4b0..6b1b5a1
Fast-forward
 b.txt | 1 +
 1 file changed, 1 insertion(+)
$ git log --decorate --abbrev-commit --stat
commit 6b1b5a1 (HEAD -> master, origin/master)
Date: Thu Feb 25 17:56:43 2016 +0100
u2 append 1x b.txt
b.txt | 1 +
 1 file changed, 1 insertion(+)
commit 7dde4b0
Date: Thu Feb 25 17:56:40 2016 +0100
u1 created b.txt
b.txt | 1 +
 1 file changed, 1 insertion(+)
commit a6dc68e
Date: Thu Feb 25 17:56:40 2016 +0100
u1 created a.txt
a.txt | 1 +
 1 file changed, 1 insertion(+)
$ git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
* 6b1b5a1 - Thu, 25 Feb 2016 17:56:43 +0100 (15 minutes ago) (HEAD -> master, origin/master)
| u2 append 1x b.txt - Bartosz Wieczorek
* 7dde4b0 - Thu, 25 Feb 2016 17:56:40 +0100 (15 minutes ago)
| u1 created b.txt - Bartosz Wieczorek
* a6dc68e - Thu, 25 Feb 2016 17:56:40 +0100 (15 minutes ago)
 u1 created a.txt - Bartosz Wieczorek

 

Scenario 2  (both users U1 and U2 are in sync; U1 modified and committed file A; U2 modified committed and pushed file B; U1 executes git pull –> automatic merge happens for file B (no conflict) and automatic merge commit is generated):

  • U1: create file A and B commits it and pushes to repo
  • U1: modifies A, commits but do not yet push
  • U2: pull changes
  • U2: modifies B, commits and pushes
  • U1: pull #no conflicts, automatically U2 commit in incorporated for U1 and automatically additional merge commit is created with message window popup
#u1
git clone https://github.com/bmwieczorek/git-pull-merge.git git-pull-merge-u1
cd git-pull-merge-u1
echo "u1 created a.txt" > a.txt
git add a.txt
git commit -m "u1 created a.txt" 
echo "u1 created b.txt" > b.txt
git add b.txt
git commit -m "u1 created b.txt"
git push origin master
echo "u1 append 1x a.txt" >> a.txt
git add a.txt
git commit -m "u1 appended a.txt" a.txt
cd ..
#u2
git clone https://github.com/bmwieczorek/git-pull-merge.git git-pull-merge-u2
cd git-pull-merge-u2
echo "u2 append 1x b.txt" >> b.txt
git add b.txt
git commit -am "u2 append 1x b.txt"
git push origin master
cd ..
#u1
cd git-pull-merge-u1
$ git pull
### MESSAGE ###
Merge branch 'master' of https://github.com/bmwieczorek/git-pull-merge
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/bmwieczorek/git-pull-tortoise-merge
 bc649c1..a2af093 master -> origin/master
Merge made by the 'recursive' strategy.
 b.txt | 1 +
 1 file changed, 1 insertion(+)
$ git log --decorate --abbrev-commit --stat
commit 3ed9f6c (HEAD -> master)
Merge: 2d7c906 a2af093
Date: Thu Feb 25 17:24:49 2016 +0100
Merge branch 'master' of https://github.com/bmwieczorek/git-pull-merge
commit a2af093 (origin/master)
Date: Thu Feb 25 17:24:41 2016 +0100
u2 append 1x b.txt
b.txt | 1 +
 1 file changed, 1 insertion(+)
commit 2d7c906
Date: Thu Feb 25 17:24:40 2016 +0100
u1 appended a.txt
a.txt | 1 +
 1 file changed, 1 insertion(+)
commit bc649c1
Date: Thu Feb 25 17:24:37 2016 +0100
u1 created b.txt
b.txt | 1 +
 1 file changed, 1 insertion(+)
commit a351e86
Date: Thu Feb 25 17:24:37 2016 +0100
u1 created a.txt
a.txt | 1 +
 1 file changed, 1 insertion(+)
$ git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
* 3ed9f6c - Thu, 25 Feb 2016 17:24:49 +0100 (2 minutes ago) (HEAD -> master)
|\ Merge branch 'master' of https://github.com/bmwieczorek/git-pull-merge - Bartosz Wieczorek
| * a2af093 - Thu, 25 Feb 2016 17:24:41 +0100 (2 minutes ago) (origin/master)
| | u2 append 1x b.txt - Bartosz Wieczorek
* | 2d7c906 - Thu, 25 Feb 2016 17:24:40 +0100 (2 minutes ago)
|/ u1 appended a.txt - Bartosz Wieczorek
* bc649c1 - Thu, 25 Feb 2016 17:24:37 +0100 (2 minutes ago)
| u1 created b.txt - Bartosz Wieczorek
* a351e86 - Thu, 25 Feb 2016 17:24:37 +0100 (2 minutes ago)
 u1 created a.txt - Bartosz Wieczorek

 

Scenario 3 (both users U1 and U2 are in sync; U1 modified and committed file A; U2 modified committed and pushed file A and B; U1 executes git pull and gets a conflict for file A –> need to resolve conflict manually, explicitly commit changes for file A and B):

  • U1: create file A and B commits it and pushes to repo
  • U1: modifies A, commits but do not yet push
  • U2: pull changes
  • U2: modifies A and B, commits and pushes
  • U1: pull # get conflict message
  • U1: resolve conflict and add A to index, commit A and ALSO  B (as B shows modified in index)
#u1
git clone https://github.com/bmwieczorek/git-pull-merge.git git-pull-merge-u1
cd git-pull-merge-u1
echo "u1 created a.txt" > a.txt
git add a.txt
git commit -m "u1 created a.txt"
echo "u1 created b.txt" > b.txt
git add b.txt
git commit -m "u1 created b.txt"
git push origin master
echo "u1 append 1x a.txt" >> a.txt
git add a.txt
git commit -m "u1 appended a.txt" a.txt
cd ..
#u2
git clone https://github.com/bmwieczorek/git-pull-merge.git git-pull-merge-u2
cd git-pull-merge-u2
echo "u2 append 1x a.txt" >> a.txt
git add b.txt
git commit -am "u2 append 1x a.txt"
echo "u2 append 1x b.txt" >> b.txt
git add b.txt
git commit -am "u2 append 1x b.txt"
git push origin master
cd ..
#u1
cd git-pull-merge-u1
git pull
$ git pull
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 0), reused 6 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), done.
From https://github.com/bmwieczorek/git-pull-merge
 8d3dab6..add5276 master -> origin/master
Auto-merging a.txt
CONFLICT (content): Merge conflict in a.txt
Automatic merge failed; fix conflicts and then commit the result.
$ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 2 different commits each, respectively.
 (use "git pull" to merge the remote branch into yours)
You have unmerged paths.
 (fix conflicts and run "git commit")
Changes to be committed:
 modified: b.txt
Unmerged paths:
 (use "git add <file>..." to mark resolution)
 both modified: a.txt
$ git diff HEAD b.txt
diff --git a/b.txt b/b.txt
index 732f593..1accd17 100644
--- a/b.txt
+++ b/b.txt
@@ -1 +1,2 @@
 u1 created b.txt
+u2 append 1x b.txt
$ cat a.txt
u1 created a.txt
<<<<<<< HEAD
u1 append 1x a.txt
||||||| merged common ancestors
=======
u2 append 1x a.txt
>>>>>>> add52769de2b4a49c07a1f3745283d262d8d94a2
$ vim a.txt
$ cat a.txt
u1 created a.txt
u1 append 1x a.txt
u2 append 1x a.txt
$ git add a.txt
$ git commit -m "u1 manually merged from upstream"
[master f99b515] u1 manually merged from upstream
$ git log --decorate --abbrev-commit --stat
commit f99b515 (HEAD -> master)
Merge: 5491dff add5276
Date: Thu Feb 25 17:44:02 2016 +0100
 u1 manually merged from upstream
commit add5276 (origin/master)
Date: Thu Feb 25 17:42:26 2016 +0100
 u2 append 1x b.txt
 b.txt | 1 +
 1 file changed, 1 insertion(+)
commit 80f95d8
Date: Thu Feb 25 17:42:26 2016 +0100
 u2 append 1x a.txt
 a.txt | 1 +
 1 file changed, 1 insertion(+)
commit 5491dff
Date: Thu Feb 25 17:42:25 2016 +0100
 u1 appended a.txt
 a.txt | 1 +
 1 file changed, 1 insertion(+)
commit 8d3dab6
Date: Thu Feb 25 17:42:23 2016 +0100
 u1 created b.txt
 b.txt | 1 +
 1 file changed, 1 insertion(+)
commit 2d142ad
Date: Thu Feb 25 17:42:23 2016 +0100
 u1 created a.txt
 a.txt | 1 +
 1 file changed, 1 insertion(+)
$ git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
* f99b515 - Thu, 25 Feb 2016 17:44:02 +0100 (56 seconds ago) (HEAD -> master)
|\ u1 manually merged from upstream - Bartosz Wieczorek
| * add5276 - Thu, 25 Feb 2016 17:42:26 +0100 (3 minutes ago) (origin/master)
| | u2 append 1x b.txt - Bartosz Wieczorek
| * 80f95d8 - Thu, 25 Feb 2016 17:42:26 +0100 (3 minutes ago)
| | u2 append 1x a.txt - Bartosz Wieczorek
* | 5491dff - Thu, 25 Feb 2016 17:42:25 +0100 (3 minutes ago)
|/ u1 appended a.txt - Bartosz Wieczorek
* 8d3dab6 - Thu, 25 Feb 2016 17:42:23 +0100 (3 minutes ago)
| u1 created b.txt - Bartosz Wieczorek
* 2d142ad - Thu, 25 Feb 2016 17:42:23 +0100 (3 minutes ago)
 u1 created a.txt - Bartosz Wieczorek
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s