Conflict Resolution
Understanding Git Conflicts
When rebasing, conflicts occur when changes in different branches modify the same lines of code. Resolving these conflicts is crucial for maintaining project integrity.
Identifying Conflicts
## Start rebase
git rebase main
## Check conflict status
git status
Conflict Markers
<<<<<<< HEAD
Current branch code
=======
Incoming branch code
>>>>>>> branch-name
Conflict Resolution Strategies
Strategy |
Command |
Description |
Manual Editing |
Direct file edit |
Manually choose code segments |
Use Current |
git checkout --ours file |
Keep current branch changes |
Use Incoming |
git checkout --theirs file |
Keep incoming branch changes |
Interactive Conflict Resolution
stateDiagram-v2
[*] --> Conflict
Conflict --> ManualEdit
ManualEdit --> StageChanges
StageChanges --> ContinueRebase
ContinueRebase --> [*]
Practical Conflict Resolution Steps
## Start rebase
git rebase main
## When conflict occurs
## 1. Open conflicting files
## 2. Manually resolve conflicts
## 3. Stage resolved files
git add resolved_file.txt
## Continue rebase
git rebase --continue
Advanced Conflict Handling
## Abort rebase if too complex
git rebase --abort
## Skip a problematic commit
git rebase --skip
Conflict Prevention Tips
- Communicate with team members
- Pull and merge frequently
- Use clear, modular code structure
LabEx recommends practicing conflict resolution in a safe environment to build confidence and skill.