Merge and Resolve
Conflict Resolution Strategies
Resolving conflicts is a critical skill in collaborative software development. Git provides multiple approaches to merge and resolve branch conflicts.
Merge Workflow
graph TD
A[Detect Conflict] --> B{Manual Resolution}
B -->|Edit Files| C[Mark Resolved]
C --> D[Stage Changes]
D --> E[Commit Merge]
Conflict Resolution Methods
Manual Resolution
## Open conflicting file
nano conflicting_file.txt
## Manually edit file, removing conflict markers
## Choose desired code sections
Tool |
Command |
Description |
vimdiff |
git mergetool --tool=vimdiff |
Terminal-based merge tool |
VSCode |
code --diff |
Visual code comparison |
KDiff3 |
git mergetool --tool=kdiff3 |
Graphical merge tool |
Resolving Specific Conflict Types
Text-Based Conflicts
## Example conflict resolution
git checkout --patch branch_name file_path
Structural Conflicts
## Prefer incoming changes
git checkout --theirs file_path
## Prefer current changes
git checkout --ours file_path
Merge Strategies
graph LR
A[Merge Strategies] --> B[Recursive]
A --> C[Octopus]
A --> D[Ours]
A --> E[Subtree]
Practical Merge Commands
## Standard merge
git merge branch_name
## Merge with no fast-forward
git merge --no-ff branch_name
## Rebase merge
git rebase branch_name
Conflict Resolution Workflow
- Fetch remote changes
- Identify conflicts
- Open conflicting files
- Manually resolve differences
- Stage resolved files
- Commit merge
Handling Complex Merges
## Abort merge if too complex
git merge --abort
## Continue after resolution
git merge --continue
Merge Conflict Best Practices
Practice |
Recommendation |
Communication |
Discuss conflicts with team |
Small Commits |
Reduce merge complexity |
Regular Synchronization |
Minimize divergence |
Use Merge Tools |
Leverage visual comparisons |
LabEx Recommendation
LabEx suggests practicing merge scenarios in controlled environments to build confidence and skill.
Advanced Merge Techniques
Selective Merge
## Cherry-pick specific commits
git cherry-pick commit_hash
Merge Squash
## Combine multiple commits
git merge --squash feature_branch
Error Handling
## Check merge status
git status
## Resolve remaining conflicts
git add resolved_files
git commit