docs(merges): document conflict resolution strategy

- Create comprehensive MERGE-CONFLICTS.md guide
- Explain manual vs automated resolution approaches
- Provide troubleshooting tips and best practices
This commit is contained in:
Newzy Developer committed 2026-10-30 10:19:53 +00:00
1 parent 0b72ae162b
commit c74aa490e6
1 file changed
+161
+161
View File
@@ -0,0 +1,161 @@
# 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:
1. Two people modify the same line(s) in different commits
2. One person deletes a line another modifies
3. 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:
```bash
# 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:
```bash
# This avoids conflicts by only moving the pointer
git merge --ff-only <branch>
```
#### Squash and Rebase Merge
For feature branches, squash commits before merging:
```bash
# 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:
```bash
# Rebase the branch onto current state
git checkout <branch>
git pull --rebase origin <source-branch>
```
### 3. Conflict Prevention
**Prevent conflicts by:**
1. **Small, focused commits** - Work on one feature at a time
2. **Frequent pulls/rebases** - Keep your branch up-to-date:
```bash
git pull origin develop --rebase
# or after each commit to avoid divergence
```
3. **Clear branch naming** - `feature/user-login` not just `user-login`
4. **Code review** - Review commits before merging
### 4. Common Merge Scenarios
#### Scenario A: Feature Branch Conflict with Develop
```bash
# 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
```bash
# 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
1. **Don't panic** - Conflicts are normal in team projects
2. **Communicate early** - If you expect conflicts, communicate with teammates
3. **Pull frequently** - Reduce conflict likelihood by keeping branches synced
4. **Small commits** - Easier to merge small changes than large chunks
5. **Code review** - Another pair of eyes can catch potential conflicts
6. **Document resolution** - Add notes in commit message if complex
## Troubleshooting Common Issues
### Issue: Conflicts keep appearing after rebase
```bash
# Skip the conflict and continue rebase later
git rebase --skip
# Or abort entirely to start over
git rebase --abort
```
### Issue: Auto-merge fails
```bash
# 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.*