Skip to content

Instantly share code, notes, and snippets.

@hslabbert
Created September 30, 2020 17:18
Show Gist options
  • Save hslabbert/f90bf109fefeeaec0356f5de40eca637 to your computer and use it in GitHub Desktop.
Save hslabbert/f90bf109fefeeaec0356f5de40eca637 to your computer and use it in GitHub Desktop.
git merge example
# set up non-conflicting changes in different branches
hslabbert@penguin:~/repos/git-example$ git branch
feature/edit1
feature/edit1_no_conflict
* master
hslabbert@penguin:~/repos/git-example$ git checkout feature/edit1
Switched to branch 'feature/edit1'
hslabbert@penguin:~/repos/git-example$ git diff HEAD~1
diff --git 1.yaml 1.yaml
index 7812f7a..14a5c53 100644
--- 1.yaml
+++ 1.yaml
@@ -1,6 +1,6 @@
file_id: 1
my_vars:
- var1: value1
+ var1: edit1
var2: value2
var3: value3
var4: value4
hslabbert@penguin:~/repos/git-example$
hslabbert@penguin:~/repos/git-example$ git checkout feature/edit1_no_conflict
Switched to branch 'feature/edit1_no_conflict'
hslabbert@penguin:~/repos/git-example$ git diff HEAD~1
diff --git 1.yaml 1.yaml
index 7812f7a..495e5d7 100644
--- 1.yaml
+++ 1.yaml
@@ -6,5 +6,5 @@ my_vars:
var4: value4
var5: value5
var6: value6
- var7: value7
+ var7: edit_no_conflict
hslabbert@penguin:~/repos/git-example$
# merge the two non-conflicting branches
hslabbert@penguin:~/repos/git-example$ git checkout master
Switched to branch 'master'
hslabbert@penguin:~/repos/git-example$ git merge feature/edit1
Updating 0a45c00..e0f2da6
Fast-forward
1.yaml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
hslabbert@penguin:~/repos/git-example$ git merge feature/edit1_no_conflict
Auto-merging 1.yaml
Merge made by the 'recursive' strategy.
1.yaml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
hslabbert@penguin:~/repos/git-example$
hslabbert@penguin:~/repos/git-example$ cat 1.yaml
file_id: 1
my_vars:
var1: edit1
var2: value2
var3: value3
var4: value4
var5: value5
var6: value6
var7: edit_no_conflict
hslabbert@penguin:~/repos/git-example$
hslabbert@penguin:~/repos/git-example$ git log --pretty=oneline
6fb0025f5349cf0a11c6af9d0d9ce4ff5417e9e8 (HEAD -> master) Merge branch 'feature/edit1_no_conflict'
e9702fdd3e904978a15f490b3e5211128b9c18eb (feature/edit1_no_conflict) edit 1.yaml without conflict
e0f2da61ff79afd4d49389bd47ab01583d5f63a3 (feature/edit1) edit1
0a45c009a2cf72c3bc22b9a24f8dbabb76dd69ea template and initial values
38e0be274183f6193fcee8aecdf3165c90db2466 README.md with initial commit
hslabbert@penguin:~/repos/git-example$
# set up a conflict
hslabbert@penguin:~/repos/git-example$ git branch
feature/edit1
feature/edit1_no_conflict
feature/edit2
feature/edit2_conflict
* master
hslabbert@penguin:~/repos/git-example$ git checkout feature/edit2
Switched to branch 'feature/edit2'
hslabbert@penguin:~/repos/git-example$ git diff HEAD~1
diff --git 2.yaml 2.yaml
index 5a59364..68aea35 100644
--- 2.yaml
+++ 2.yaml
@@ -1,6 +1,6 @@
file_id: 2
my_vars:
- var1: value1
+ var1: edit2_value
var2: value2
var3: value3
var4: value4
hslabbert@penguin:~/repos/git-example$
hslabbert@penguin:~/repos/git-example$ git checkout feature/edit2_conflict
Switched to branch 'feature/edit2_conflict'
hslabbert@penguin:~/repos/git-example$ git diff HEAD~1
diff --git 2.yaml 2.yaml
index 5a59364..b60eeaa 100644
--- 2.yaml
+++ 2.yaml
@@ -1,6 +1,6 @@
file_id: 2
my_vars:
- var1: value1
+ var1: edit_2_conflicting
var2: value2
var3: value3
var4: value4
hslabbert@penguin:~/repos/git-example$
# try merging with a conflict
hslabbert@penguin:~/repos/git-example$ git checkout master
Switched to branch 'master'
hslabbert@penguin:~/repos/git-example$ git merge feature/edit2
Updating 6fb0025..15d47d0
Fast-forward
2.yaml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
hslabbert@penguin:~/repos/git-example$ git merge feature/edit2_conflict
Auto-merging 2.yaml
CONFLICT (content): Merge conflict in 2.yaml
Automatic merge failed; fix conflicts and then commit the result.
hslabbert@penguin:~/repos/git-example$
hslabbert@penguin:~/repos/git-example$ git status
On branch master
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: 2.yaml
no changes added to commit (use "git add" and/or "git commit -a")
hslabbert@penguin:~/repos/git-example$
hslabbert@penguin:~/repos/git-example$ cat 2.yaml
file_id: 2
my_vars:
<<<<<<< HEAD
var1: edit2_value
=======
var1: edit_2_conflicting
>>>>>>> feature/edit2_conflict
var2: value2
var3: value3
var4: value4
var5: value5
var6: value6
var7: value7
hslabbert@penguin:~/repos/git-example$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment