Git pull (with merge)

Scenario:
U1 clone repo, create file, commit and push origin master
U1 first update file, commit (do not yet push)
U2 clone repo, update file, commit and push origin master
U1 second update file, commit, and try to push (rejected push)
U1 git pull, resolve conflict, commit, push origin master

History after pull (with merge): chronological + additional commit for resolved conflict change
U1 merge commit
U1 second update file 
U2 update file
U1 first update file
U1 commit (file create)
Commands:
mkdir -p git-pull-merge/u1
mkdir -p git-pull-merge/u2
cd git-pull-merge/u1
git clone https://github.com/bmwieczorek/git-pull-merge.git
cd git-pull-merge
echo "u1: initial create of file.txt" >> file.txt
git add file.txt
git commit -m "u1: created file.txt" file.txt
git push origin master
echo "u1: append 1x file.txt" >> file.txt
git add file.txt
git commit -m "u1: append 1x file.txt"
# do not push yet
cd ../../u2
git clone https://github.com/bmwieczorek/git-pull-merge.git
cd git-pull-merge
echo "u2: append 1x" >> file.txt
git add file.txt
git commit -m "u2: append 1x file.txt" file.txt
git push origin master
cd ../../u1/git-pull-merge
echo "u1: append 2x file.txt" >> file.txt
git add file.txt
git commit -m "u1: append 2x file.txt"
git push origin master
git log --pretty=oneline --abbrev-commit --decorate
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
git pull
git status
cat file.txt
cat file.txt | egrep -v '<<<|>>>|===' > file.txt # resolve conflict
cat file.txt
git log --pretty=oneline --abbrev-commit --decorate
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
cat .git/FETCH_HEAD
cat .git/MERGE_HEAD
cat .git/HEAD
cat .git/ORIG_HEAD
git add file.txt
git status
git commit -m "U1: merged local commits with origin/master (U2) commit"
cat file.txt
git status
git log --pretty=oneline --abbrev-commit --decorate #
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
git push origin master
git log --pretty=oneline --abbrev-commit --decorate
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
Results:
$ mkdir -p git-pull-merge/u1
$ mkdir -p git-pull-merge/u2
$ cd git-pull-merge/u1
$ git clone https://github.com/bmwieczorek/git-pull-merge.git
Cloning into 'git-pull-merge'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.
$ cd git-pull-merge
$ echo "u1: initial create of file.txt" >> file.txt
$ git add file.txt
$ git commit -m "u1: created file.txt" file.txt
[master (root-commit) 380d5d9] u1: created file.txt
 1 file changed, 1 insertion(+)
 create mode 100644 file.txt
$ git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 255 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://bmwieczorek@github.com/bmwieczorek/git-pull-merge.git
 * [new branch] master -> master
$ echo "u1: append 1x file.txt" >> file.txt
$ git add file.txt
$ git commit -m "u1: append 1x file.txt"
[master c0d4167] u1: append 1x file.txt
 1 file changed, 1 insertion(+)
$ # do not push yet
$ cd ../../u2
$ git clone https://github.com/bmwieczorek/git-pull-merge.git
Cloning into 'git-pull-merge'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
Checking connectivity... done.
$ cd git-pull-merge
$ echo "u2: append 1x" >> file.txt
$ git add file.txt
$ git commit -m "u2: append 1x file.txt" file.txt
[master 98cfc13] u2: append 1x file.txt
 1 file changed, 1 insertion(+)
$ git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 301 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://bmwieczorek@github.com/bmwieczorek/git-pull-merge.git
 380d5d9..98cfc13 master -> master
$ cd ../../u1/git-pull-merge
$ echo "u1: append 2x file.txt" >> file.txt
$ git add file.txt
$ git commit -m "u1: append 2x file.txt"
[master d5eff05] u1: append 2x file.txt
 1 file changed, 1 insertion(+)
$ git push origin master
To https://bmwieczorek@github.com/bmwieczorek/git-pull-merge.git
 ! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://bmwieczorek@github.com/bmwieczorek/git-pull-merge.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
$ git log --pretty=oneline --abbrev-commit --decorate
d5eff05 (HEAD -> master) u1: append 2x file.txt
c0d4167 u1: append 1x file.txt
380d5d9 (origin/master) u1: created file.txt
$ 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
* d5eff05 - Mon, 15 Feb 2016 21:52:36 +0100 (28 seconds ago) (HEAD -> master)
| u1: append 2x file.txt - Bartosz Wieczorek
* c0d4167 - Mon, 15 Feb 2016 21:50:48 +0100 (2 minutes ago)
| u1: append 1x file.txt - Bartosz Wieczorek
* 380d5d9 - Mon, 15 Feb 2016 21:50:33 +0100 (3 minutes ago) (origin/master)
 u1: created file.txt - Bartosz Wieczorek
$ git pull
remote: Counting objects: 3, 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
 380d5d9..98cfc13 master -> origin/master
Auto-merging file.txt
CONFLICT (content): Merge conflict in file.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 2 and 1 different commit each, respectively.
 (use "git pull" to merge the remote branch into yours)
You have unmerged paths.
 (fix conflicts and run "git commit")
Unmerged paths:
 (use "git add <file>..." to mark resolution)
 both modified: file.txt
no changes added to commit (use "git add" and/or "git commit -a")
$ cat file.txt
u1: initial create of file.txt
<<<<<<< HEAD
u1: append 1x file.txt
u1: append 2x file.txt
=======
u2: append 1x
>>>>>>> 98cfc134c2c14d8115ae5fc9003ac1e13ba93ebb
$ cat file.txt | egrep -v '<<<|>>>|===' > file.txt # resolve conflict
$ cat file.txt
u1: initial create of file.txt
u1: append 1x file.txt
u1: append 2x file.txt
u2: append 1x
$ git log --pretty=oneline --abbrev-commit --decorate
d5eff05 (HEAD -> master) u1: append 2x file.txt
c0d4167 u1: append 1x file.txt
380d5d9 u1: created file.txt
$ 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
* d5eff05 - Mon, 15 Feb 2016 21:52:36 +0100 (62 seconds ago) (HEAD -> master)
| u1: append 2x file.txt - Bartosz Wieczorek
* c0d4167 - Mon, 15 Feb 2016 21:50:48 +0100 (3 minutes ago)
| u1: append 1x file.txt - Bartosz Wieczorek
| * 98cfc13 - Mon, 15 Feb 2016 21:52:01 +0100 (2 minutes ago) (origin/master)
|/ u2: append 1x file.txt - Bartosz Wieczorek
* 380d5d9 - Mon, 15 Feb 2016 21:50:33 +0100 (3 minutes ago)
 u1: created file.txt - Bartosz Wieczorek
$ cat .git/FETCH_HEAD
98cfc134c2c14d8115ae5fc9003ac1e13ba93ebb branch 'master' of https://github.com/bmwieczorek/git-pull-merge
$ cat .git/MERGE_HEAD
98cfc134c2c14d8115ae5fc9003ac1e13ba93ebb
$ cat .git/HEAD
ref: refs/heads/master
$ cat .git/ORIG_HEAD
d5eff058422f02df955b50499d9399ff0d174ebb
$ git add file.txt
$ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 2 and 1 different commit each, respectively.
 (use "git pull" to merge the remote branch into yours)
All conflicts fixed but you are still merging.
 (use "git commit" to conclude merge)
Changes to be committed:
 modified: file.txt
$ git commit -m "U1: merged local commits with origin/master (U2) commit"
[master edf2634] U1: merged local commits with origin/master (U2) commit
$ cat file.txt
u1: initial create of file.txt
u1: append 1x file.txt
u1: append 2x file.txt
u2: append 1x
$ git status
On branch master
Your branch is ahead of 'origin/master' by 3 commits.
 (use "git push" to publish your local commits)
nothing to commit, working directory clean
$ git log --pretty=oneline --abbrev-commit --decorate # note additional commit for resolved conflict change and chronological commits
edf2634 (HEAD -> master) U1: merged local commits with origin/master (U2) commit
d5eff05 u1: append 2x file.txt
98cfc13 (origin/master) u2: append 1x file.txt
c0d4167 u1: append 1x file.txt
380d5d9 u1: created file.txt
$ 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
* edf2634 - Mon, 15 Feb 2016 21:54:24 +0100 (20 seconds ago) (HEAD -> master)
|\ U1: merged local commits with origin/master (U2) commit - Bartosz Wieczorek
| * 98cfc13 - Mon, 15 Feb 2016 21:52:01 +0100 (3 minutes ago) (origin/master)
| | u2: append 1x file.txt - Bartosz Wieczorek
* | d5eff05 - Mon, 15 Feb 2016 21:52:36 +0100 (2 minutes ago)
| | u1: append 2x file.txt - Bartosz Wieczorek
* | c0d4167 - Mon, 15 Feb 2016 21:50:48 +0100 (4 minutes ago)
|/ u1: append 1x file.txt - Bartosz Wieczorek
* 380d5d9 - Mon, 15 Feb 2016 21:50:33 +0100 (4 minutes ago)
 u1: created file.txt - Bartosz Wieczorek
$ git push origin master
Counting objects: 9, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (9/9), 815 bytes | 0 bytes/s, done.
Total 9 (delta 2), reused 0 (delta 0)
To https://bmwieczorek@github.com/bmwieczorek/git-pull-merge.git
 98cfc13..edf2634 master -> master
$ git log --pretty=oneline --abbrev-commit --decorate
edf2634 (HEAD -> master, origin/master) U1: merged local commits with origin/master (U2) commit
d5eff05 u1: append 2x file.txt
98cfc13 u2: append 1x file.txt
c0d4167 u1: append 1x file.txt
380d5d9 u1: created file.txt
$ 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
* edf2634 - Mon, 15 Feb 2016 21:54:24 +0100 (64 seconds ago) (HEAD -> master, origin/master)
|\ U1: merged local commits with origin/master (U2) commit - Bartosz Wieczorek
| * 98cfc13 - Mon, 15 Feb 2016 21:52:01 +0100 (3 minutes ago)
| | u2: append 1x file.txt - Bartosz Wieczorek
* | d5eff05 - Mon, 15 Feb 2016 21:52:36 +0100 (3 minutes ago)
| | u1: append 2x file.txt - Bartosz Wieczorek
* | c0d4167 - Mon, 15 Feb 2016 21:50:48 +0100 (5 minutes ago)
|/ u1: append 1x file.txt - Bartosz Wieczorek
* 380d5d9 - Mon, 15 Feb 2016 21:50:33 +0100 (5 minutes ago)
 u1: created file.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