Code conflicts are not scary. What’s scary is improvising during a conflict, messing up the history, and breaking the logic. This article gives you a Standard Operating Procedure (SOP) for handling conflicts, suitable for team collaboration scenarios.
1. First Determine: Are You Merging or Rebasing?
Command:
git statusIf it says rebase in progress, the handling method is different from a merge.
2. Three Principles Before Handling Conflicts
- Ensure the code semantics are correct first, then pursue a clean history.
- Do not make extra requirement changes during the conflict resolution phase.
- Resolve one small chunk at a time, and run tests promptly.
3. Merge Conflict Handling Process
git pull origin main# After conflicts appear, edit the conflicting files# Delete the <<<<<<< ======= >>>>>>> markers
git add <resolved-files>git commit4. Rebase Conflict Handling Process
git fetch origingit rebase origin/main# Fix conflicts
git add <resolved-files>git rebase --continueIf you realize your rebase route is wrong:
git rebase --abort5. The 5 Most Common Types of Conflicts
- The exact same line modified by both sides simultaneously.
- File renaming occurring simultaneously with content modification.
- Conflicting file deletion vs. file editing.
- Frequent conflicts in lock files (e.g.,
package-lock.json). - Automatic formatting tools causing massive meaningless diffs.
6. Practical Tips
git diff --name-only --diff-filter=U: Only show conflicting files.- Resolve core business files first, then handle configuration or formatting files.
- Try to resolve lock file conflicts by regenerating them, avoid manually editing complex sections.
7. Post-Conflict Regression Check
Execute at least the following:
- Project build.
- Core test cases.
- Manual smoke testing of critical pages.
This step cannot be skipped, otherwise, “the conflict is resolved, but the feature is broken.”
8. Prevention at the Team Level
- Small, frequent commits to reduce massive PRs.
- Sync long-running branches with upstream daily.
- Run CI before merging.
- Unify formatter and lint rules.
Summary
Conflict resolution is not a technical dilemma, but an engineering discipline issue. With established processes, boundaries, and regression checks, conflicts will no longer be a black hole for team efficiency.
If this article helped you, please share it with others!
Some information may be outdated





