You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/branches.md
+70Lines changed: 70 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -278,6 +278,8 @@ graph LR
278
278
279
279
Merge 'cool-feature' to 'master' (3-way merge)
280
280
281
+
3-way merges use a dedicated commit for connecting the two merge histories. The name comes from the fact that Git uses three commits to generate the merge commit: the two branch tips and their common ancestor.
282
+
281
283
```mermaid
282
284
graph LR
283
285
@@ -335,6 +337,74 @@ graph LR
335
337
336
338
---
337
339
340
+
### Example, fast-forward merging
341
+
342
+
If there is a linear path from the current branch tip and to the target branch, then it is possible to do a fast-forward merge. Git is not really merging the branches, just integrating the histories, i.e. it moves “fast forward” the current branch tip up to the target branch tip.
343
+
344
+
When doing so the commit histories are combined and all commit histories can be reached from the current tip. An example would be to do a fast-forward merge of a feature into master/main.
345
+
346
+
A fast-forward merge is not possible if the branches have diverged, like in the previous example. This means that there is no linear path to the target branch and Git has to combine them via a 3-way merge.
347
+
348
+
This shows an example where a fast-forward merge would work.
349
+
350
+
Before FF merge:
351
+
352
+
```mermaid
353
+
graph LR
354
+
355
+
master["master"]
356
+
style master fill:#ffffff,stroke:#ffffff
357
+
nice-feature["nice-feature"]
358
+
style nice-feature fill:#ffffff,stroke:#ffffff
359
+
360
+
commitX(["commitX"])
361
+
commit1(["commit1"])
362
+
commit2(["commit2"])
363
+
commitY(["commitY"])
364
+
commit3(["commit3"])
365
+
commit4(["commit4"])
366
+
commit4Y(["New merge commit"])
367
+
368
+
master -.-> commit4
369
+
commit4 --> commit3
370
+
commit4 --> commit4Y
371
+
cool-feature -.-> commitY
372
+
commit3 --> commit2
373
+
commit2 --> commit1
374
+
commitY --> commitX
375
+
commitY --> commit4Y
376
+
commitX --> commit1
377
+
```
378
+
379
+
After FF merge:
380
+
381
+
```mermaid
382
+
graph LR
383
+
384
+
master["master"]
385
+
style master fill:#ffffff,stroke:#ffffff
386
+
cool-feature["cool-feature"]
387
+
style cool-feature fill:#ffffff,stroke:#ffffff
388
+
389
+
commitX(["commitX"])
390
+
commit1(["commit1"])
391
+
commit2(["commit2"])
392
+
commitY(["commitY"])
393
+
commit3(["commit3"])
394
+
commit4(["commit4"])
395
+
commit4Y(["New merge commit"])
396
+
397
+
master -.-> commit4
398
+
commit4 --> commit3
399
+
commit4 --> commit4Y
400
+
cool-feature -.-> commitY
401
+
commit3 --> commit2
402
+
commit2 --> commit1
403
+
commitY --> commitX
404
+
commitY --> commit4Y
405
+
commitX --> commit1
406
+
```
407
+
338
408
## Switching with uncommitted changes
339
409
340
410
As mentioned above, you switch between branches with:
0 commit comments