mobile wallpaper 1mobile wallpaper 2mobile wallpaper 3mobile wallpaper 4
287 words
1 minute
Git Conflict Resolution Playbook: A Standard Process from Location to Convergence

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 status

If it says rebase in progress, the handling method is different from a merge.

2. Three Principles Before Handling Conflicts#

  1. Ensure the code semantics are correct first, then pursue a clean history.
  2. Do not make extra requirement changes during the conflict resolution phase.
  3. 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 commit

4. Rebase Conflict Handling Process#

git fetch origin
git rebase origin/main
# Fix conflicts
git add <resolved-files>
git rebase --continue

If you realize your rebase route is wrong:

git rebase --abort

5. The 5 Most Common Types of Conflicts#

  1. The exact same line modified by both sides simultaneously.
  2. File renaming occurring simultaneously with content modification.
  3. Conflicting file deletion vs. file editing.
  4. Frequent conflicts in lock files (e.g., package-lock.json).
  5. 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:

  1. Project build.
  2. Core test cases.
  3. 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.

Share

If this article helped you, please share it with others!

Git Conflict Resolution Playbook: A Standard Process from Location to Convergence
https://blog.levifree.com/posts/git-conflict-resolution-playbook/
Author
LeviFREE
Published at
2024-12-03
License
CC BY-NC-SA 4.0

Some information may be outdated

Table of Contents