- Create comprehensive MERGE-CONFLICTS.md guide - Explain manual vs automated resolution approaches - Provide troubleshooting tips and best practices
4.3 KiB
4.3 KiB
Merge Conflict Resolution Strategy
Overview
This document describes the standard approach for handling merge conflicts in the newzy project. Understanding these strategies helps maintain a clean repository history and smooth team collaboration.
When Merge Conflicts Occur
Merge conflicts happen when:
- Two people modify the same line(s) in different commits
- One person deletes a line another modifies
- Multiple conflicting changes are made to overlapping code blocks
Conflict Resolution Strategies
1. Manual Conflict Resolution (Recommended)
For significant changes or complex files, manual resolution is preferred:
# Navigate to the conflicting file and use your editor
git status # See which files have conflicts
git checkout <file> # Open in your editor
# Resolve conflicts manually
git add <file> # Mark as resolved
Manual Resolution Tips:
- Read both conflict markers carefully (
<<<<<<<,=======,>>>>>>>) - Understand what each side changed
- Choose the best solution for functionality
- Test thoroughly after resolution
- Write clear commit message explaining resolution
2. Automated Merge Strategies
Fast-forward Merges (Preferred)
When no conflicts exist, use fast-forward merges:
# This avoids conflicts by only moving the pointer
git merge --ff-only <branch>
Squash and Rebase Merge
For feature branches, squash commits before merging:
# Author rebases their feature onto develop
git checkout feature-branch
git rebase -i develop
# Then merge with squash
git checkout develop
git merge --squash feature-branch
git commit -m "Merge 'feature/xxx' into develop"
Rebase Merges (Maintainer Only)
For maintaining clean history, maintainers can:
# Rebase the branch onto current state
git checkout <branch>
git pull --rebase origin <source-branch>
3. Conflict Prevention
Prevent conflicts by:
- Small, focused commits - Work on one feature at a time
- Frequent pulls/rebases - Keep your branch up-to-date:
git pull origin develop --rebase # or after each commit to avoid divergence - Clear branch naming -
feature/user-loginnot justuser-login - Code review - Review commits before merging
4. Common Merge Scenarios
Scenario A: Feature Branch Conflict with Develop
# In your feature branch
git checkout feature/xxx
git pull origin develop --rebase
# Resolve conflicts in your editor
# Then continue rebase
git rebase --continue
Scenario B: Merging into Main from Hotfix
# Merge hotfix to both main and develop
git checkout main
git merge --no-ff hotfix/critical-fix
git push origin main
git checkout develop
git merge --no-ff <hotfix-branch>
git push origin develop
Automated Tools
VS Code (Built-in)
- Quick Fix: Auto-accepts or rejects changes
- Merge Manually: Full control in editor UI
- Command Palette: Resolve all, resolve current only
Git GUI Tools
- GitHub Desktop
- GitKraken
- SourceTree
- Fork
Conflict Resolution Checklist
When resolving conflicts:
- Understand why the conflict occurred
- Read both conflicting versions carefully
- Determine which change makes more sense functionally
- Test the resolved code thoroughly
- Ensure no functionality is lost
- Commit with descriptive message explaining resolution
- Run full test suite before merging
Best Practices
- Don't panic - Conflicts are normal in team projects
- Communicate early - If you expect conflicts, communicate with teammates
- Pull frequently - Reduce conflict likelihood by keeping branches synced
- Small commits - Easier to merge small changes than large chunks
- Code review - Another pair of eyes can catch potential conflicts
- Document resolution - Add notes in commit message if complex
Troubleshooting Common Issues
Issue: Conflicts keep appearing after rebase
# Skip the conflict and continue rebase later
git rebase --skip
# Or abort entirely to start over
git rebase --abort
Issue: Auto-merge fails
# Use merge tool for complex cases
git mergetool
# Or resolve manually with editor
nano .<filename>.orig.<branch>
Remember: A well-resolved conflict is often better than no merge at all.