0
0
Gitdevops~10 mins

Three-way merge in Git - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Three-way merge
Start: Common Base Commit
Branch A changes
Three-way merge compares
Merge result with combined changes
Commit merge
The three-way merge compares two changed versions with their common base to combine changes into one merged result.
Execution Sample
Git
git checkout branchA
# make changes and commit

git checkout branchB
# make changes and commit

git merge branchA
This sequence merges changes from branchA into branchB using a three-way merge.
Process Table
StepActionBase VersionBranch A VersionBranch B VersionMerge ResultNotes
1Identify common base commitBase file contentBase file contentBase file contentN/AAll start from same base
2Compare base to Branch ABase file contentChanged line in ABase file contentN/ADetect changes made in Branch A
3Compare base to Branch BBase file contentBase file contentChanged line in BN/ADetect changes made in Branch B
4Merge changesBase file contentChanged line in AChanged line in BCombined changes or conflict markersIf changes overlap, conflict occurs
5Resolve conflicts if anyN/AN/AN/AFinal merged contentUser edits conflicts manually
6Commit mergeN/AN/AN/AMerge commit createdMerge is complete
💡 Merge commit created or conflicts resolved and committed
Status Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5Final
Base file contentOriginal textOriginal textOriginal textOriginal textOriginal textOriginal text
Branch A file contentOriginal textChanged line in AChanged line in AChanged line in AChanged line in A or resolvedFinal merged content
Branch B file contentOriginal textOriginal textChanged line in BChanged line in BChanged line in B or resolvedFinal merged content
Merge resultN/AN/AN/ACombined changes or conflict markersFinal merged contentFinal merged content
Key Moments - 3 Insights
Why does git need a common base commit for merging?
Git uses the common base commit to understand what changed in each branch separately. This helps it combine changes correctly or detect conflicts, as shown in execution_table rows 1-3.
What happens if both branches change the same line differently?
Git marks a conflict in the merge result (row 4). The user must manually resolve it (row 5) before committing the merge (row 6).
Can a merge happen without conflicts?
Yes, if changes are on different lines or parts, git automatically combines them (row 4) and creates a merge commit (row 6).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 4. What does the 'Merge Result' show if both branches changed the same line differently?
AConflict markers showing both changes
BOnly Branch A changes
CCombined changes without any markers
DOnly Branch B changes
💡 Hint
Refer to execution_table row 4 under 'Merge Result' and 'Notes' columns.
At which step does the user manually resolve conflicts?
AStep 3
BStep 4
CStep 5
DStep 6
💡 Hint
Check execution_table row 5 'Action' and 'Notes' columns.
If Branch A made no changes, what would the merge result be at step 4?
AConflict markers appear
BMerge result equals Branch B version
CMerge result equals Base version
DMerge fails
💡 Hint
Look at variable_tracker for Branch A and Branch B content changes after step 4.
Concept Snapshot
Three-way merge in git:
- Uses common base commit plus two branch versions
- Compares changes from base to each branch
- Combines non-conflicting changes automatically
- Marks conflicts if same lines changed differently
- User resolves conflicts manually
- Final merge commit records combined history
Full Transcript
A three-way merge in git starts by identifying the common base commit shared by two branches. Then git compares the base version with each branch's version to find changes. If changes do not overlap, git automatically combines them into a merged result. If both branches changed the same lines differently, git marks conflicts in the merged file. The user must manually resolve these conflicts before committing the merge. The final merge commit records the combined changes and history from both branches.