@@ -11,14 +11,25 @@ resources: {
1111
1212Merging combines the work from different branches back together.
1313
14+ This creates a merge commit. Merge commits are special because they
15+ have more than 1 parent commit.
16+
17+ ---
18+
1419Before merge:
1520![ example-before-merge] ( https://git-scm.com/book/en/v2/images/basic-merging-1.png )
1621
22+ > Notice that master and iss53 have commits
23+ > exclusive to each side
24+
1725---
1826
1927After merge:
2028![ example-after-merge] ( https://git-scm.com/book/en/v2/images/basic-merging-2.png )
2129
30+ > Notice that commit C6 has 2 parent commits:
31+ > C5 and C4
32+
2233---
2334
2435## Listing merged / unmerged branches
@@ -35,19 +46,8 @@ git branch --no-merged
3546
3647## Fast-Forward Merge
3748
38- When the target branch hasn't changed since the feature branch was created:
39-
40- ```
41- Before merge:
42- main: A---B---C
43- \
44- feature: D---E
45-
46- After merge:
47- main: A---B---C---D---E
48- ```
49-
50- ---
49+ When the target branch hasn't changed since the feature branch was created.
50+ No merge commit is created. The history remains linear.
5151
5252``` bash
5353# Switch to main branch
@@ -64,26 +64,12 @@ git merge main feature-branch
6464
6565## Real Merge
6666
67- When both branches have new commits:
68-
69- ```
70- Before merge:
71- main: A---B---C---F
72- \
73- feature: D---E
74-
75- After merge:
76- main: A---B---C---F---G
77- \ /
78- feature: D---E---/
79- ```
80-
81- ---
67+ When both branches have new commits a merge commit is created:
8268
8369``` bash
8470git checkout main
8571git merge feature-branch
86- # Creates merge commit G
72+ # Creates a new merge commit
8773```
8874
8975<bonus-content >
@@ -118,8 +104,9 @@ git log --oneline --graph
118104
119105Conflicts occur when the same lines in the same files are changed differently on two branches.
120106
121- Git is usually smart enough to resolve trivial conflicts automatically,
122- but when it is not clear what the outcome should be - you need to resolve manually.
107+ Git is usually smart enough to resolve trivial conflicts automatically.
108+
109+ But when it is not clear what the outcome should be - you need to resolve manually.
123110
124111---
125112
@@ -141,9 +128,9 @@ git merge main feature-greeting
141128
142129---
143130
144- ### Conflict Resolution
131+ ## Conflict Resolution
145132
146- When a conflict occurs, Git modifies the file to show both versions:
133+ When a conflict occurs, Git ** modifies** the file to show both versions:
147134
148135```
149136<<<<<<< HEAD
@@ -153,13 +140,15 @@ Hello World from feature
153140>>>>>>> feature-greeting
154141```
155142
143+ Git will also prevent you from committing until the conflict is resolved.
144+
156145---
157146
158- To resolve:
147+ To resolve, edit the files so the correct version of the content is present. Then ` add ` and ` commit ` :
159148
160149``` bash
161150# 1. Edit the file to choose the version you want
162- echo " Hello World - combined version " > greeting.txt
151+ nvim # btw
163152
164153# 2. Stage the resolved file
165154git add greeting.txt
@@ -172,13 +161,17 @@ git commit -m "merge: resolve greeting conflict"
172161
173162### Conflict Resolution Tools
174163
175- ``` bash
176- # Use visual merge tool
177- git mergetool
164+ There are many tools that allow for easier view of conflicts.
165+
166+ Git can be configured to use a specific ` mergetool `
178167
168+ ``` bash
179169# Abort the merge and start over
180170git merge --abort
181171
172+ # Use visual merge tool
173+ git mergetool
174+
182175# Show conflicts in different format
183176git diff --name-only --diff-filter=U
184177```
@@ -187,7 +180,7 @@ git diff --name-only --diff-filter=U
187180
188181## Rebasing
189182
190- Rebasing rewrites history to create a cleaner, linear timeline :
183+ Rebasing ** rewrites history** to create a cleaner, linear commit history :
191184
192185``` bash
193186# Instead of merge, use rebase
@@ -198,8 +191,8 @@ git rebase main
198191git rebase -i HEAD~3
199192```
200193
201- ** When to use ** : Cleaning up feature branch before merging
202- ** When NOT to use ** : On shared/public branches
194+ - ** Use when ** : Cleaning up feature branch before merging
195+ - ** DONT'T USE ** : On shared/public branches
203196
204197---
205198
@@ -233,17 +226,22 @@ git checkout original-branch
233226git stash pop
234227```
235228
236- ---
229+ < bonus-content >
237230
238- ## Abort / Continue options
231+ < pop-quiz data-answer-id = " 3 " >
239232
240- <!-- TODO: write this -->
233+ ### When does a merge cause a conflict?
241234
242- <bonus-content >
235+ - two cars want to drive in the same lane
236+ - two repositories have the same name
237+ - two coworkers reach for the same soda can
238+ - two branches being merged have diverging content
239+
240+ </pop-quiz >
243241
244242<home-work >
245243
246- ### Assignment 2: Remote Collaboration Simulation
244+ ### Remote Collaboration Simulation
247245
2482461 . Create a repository on GitHub
2492472 . Clone it to two different directories (simulating two developers)
0 commit comments