GitHub合并方向异常咨询:master向handtracking合并出错
Hey there, let's walk through what went wrong with your merge, explain the confusing bits, and cover how to avoid this next time.
1. 异常原因与操作失误分析
Your core issue stems from how you handled conflicts in the GitHub web UI combined with a subtle quirk in PR merge logic:
- When you created the PR from
mastertohandtracking, GitHub detected conflicts. When you chose to resolve them via the web editor, you likely ended up committing those conflict fixes directly to themasterbranch (instead of a dedicated conflict-resolution branch tied to the PR). This happened because the web editor's context might have defaulted tomasterwhen you opened it, or you accidentally selectedmasteras the target for the conflict commit. - Once you pushed that conflict fix to
master, you alteredmaster's commit history. When you went to merge the PR, GitHub's system saw thatmasternow had new commits thathandtrackingdidn't—but also that the original PR's direction wasmaster→handtracking, so it tried to reconcile this messy state by first merginghandtrackingintomaster(to "catch up"masterwith olderhandtrackingcommits that weren't inmasteranymore) before merging the updatedmasterinto a newhandtrackingref.
2. 解释反向合并(handtracking → master)的来源
That unexpected handtracking → master merge wasn't a random glitch—it was GitHub's attempt to fix the inconsistent state you created:
- After you committed conflict fixes directly to
master,masterhad new commits, buthandtrackingstill had unique development commits that weren't present in the updatedmaster. - When you clicked the PR merge button, GitHub's merge logic tried to resolve the divergence: it first merged
handtrackingintomasterto ensuremastercontained all commits from both branches, then merged that combinedmasterback tohandtracking. Even though the PR UI showedmaster→handtracking, the alteredmasterhistory broke the expected flow. - The missing commit records? Those conflict-resolution commits might have been overwritten by the reverse merge, or they're buried in the merge commit's history—try checking
master's commit log with "Show merged commits" enabled to find them.
3. 避免此类问题的操作建议(无需命令行)
You absolutely don't need to use the command line to do this correctly—here's the safe, repeatable workflow using GitHub Desktop:
- Step 1: Prep your branches
- Make sure all local changes are committed and synced in both
masterandhandtracking. - Switch to the
masterbranch in GitHub Desktop, click "Pull origin" to get the latest remotemasterupdates.
- Make sure all local changes are committed and synced in both
- Step 2: Merge
masterintohandtrackinglocally- Switch to the
handtrackingbranch in GitHub Desktop. - Go to the Branch menu → select Merge into current branch → choose
masterfrom the dropdown.
- Switch to the
- Step 3: Resolve conflicts locally (way safer than web UI)
- If conflicts pop up, GitHub Desktop will prompt you to resolve them using your local code editor. This keeps all conflict fixes in the
handtrackingbranch context, so you can't accidentally commit tomaster. - Once conflicts are fixed, commit the merge to your local
handtrackingbranch.
- If conflicts pop up, GitHub Desktop will prompt you to resolve them using your local code editor. This keeps all conflict fixes in the
- Step 4: Sync the updated
handtrackingbranch- Click "Push origin" in GitHub Desktop to send the merged
handtrackingbranch to remote.
- Click "Push origin" in GitHub Desktop to send the merged
- Optional: Use a PR for visibility (if needed)
- If you want a PR to document the merge or get review, create one from
mastertohandtrackingafter you've merged locally and pushed—there will be no conflicts, so it can merge cleanly with one click.
- If you want a PR to document the merge or get review, create one from
The key difference from your failed attempt is resolving conflicts locally in the target branch (handtracking) instead of the web UI, which eliminates the risk of accidental commits to master.
内容的提问来源于stack exchange,提问作者Jason C

