协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
resolve-git-conflicts【开发与工程】Resolve merge and rebase conflicts with safe recovery strategies. Covers identifying conflict sources, reading conflict markers, choosing resolution strategies, and continuing or aborting operations safely. Use when a git merge, rebase, cherry-pick, or stash pop reports conflicts, when a git pull results in conflicting changes, or when you need to sa…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
識、解、復合與變基之衝。
git merge 或 git rebase 報衝乃用git cherry-pick 不能淨施乃用git pull 致衝之變乃用git stash pop 與當工作樹衝乃用定何操致衝:
# Check current status
git status
# Look for indicators:
# "You have unmerged paths" — merge conflict
# "rebase in progress" — rebase conflict
# "cherry-pick in progress" — cherry-pick conflict
狀之出告何文有衝、何操進中。
得:git status 示「Unmerged paths」之文與進中之操。
敗則:若 git status 示淨樹而期衝,操或已畢或已棄。察 git log 之近活。
開各衝文而定衝之標:
<<<<<<< HEAD
// Your current branch's version
const result = calculateWeightedMean(data, weights);
=======
// Incoming branch's version
const result = computeWeightedAverage(data, weights);
>>>>>>> feature/rename-functions
<<<<<<< HEAD 至 =======:當枝(或正變基至之枝)======= 至 >>>>>>>:來變(合之枝或施之提交)得:各衝文含一或數塊附 <<<<<<<、=======、>>>>>>> 之標。
敗則:若無標而文示為衝,衝或為二進制文或刪對改之衝。察 git diff --name-only --diff-filter=U 為全列。
手合(最常):編文以邏輯合二變,後除諸衝標。
受 ours(留當枝之版):
# For a single file
git checkout --ours path/to/file.R
git add path/to/file.R
# For all conflicts
git checkout --ours .
git add -A
受 theirs(留來枝之版):
# For a single file
git checkout --theirs path/to/file.R
git add path/to/file.R
# For all conflicts
git checkout --theirs .
git add -A
得:解後文含正合之內,無餘衝標。
敗則:若擇誤側,再讀自合基之衝版。合間,git checkout -m path/to/file 重立衝標以再試。
各衝文編後:
# Stage the resolved file
git add path/to/resolved-file.R
# Check remaining conflicts
git status
「Unmerged paths」之諸文皆然。
得:諸文自「Unmerged paths」移至「Changes to be committed」。無文留衝標。
敗則:若 git add 敗或標留,再開文而確諸 <<<<<<<、=======、>>>>>>> 行皆除。
諸衝既解:
為合:
git commit
# Git auto-populates the merge commit message
為變基:
git rebase --continue
# May encounter more conflicts on subsequent commits — repeat steps 2-4
為 cherry-pick:
git cherry-pick --continue
為 stash pop:
# Stash pop conflicts don't need a continue — just commit or reset
git add .
git commit -m "Apply stashed changes with conflict resolution"
得:操畢。git status 示淨工作樹(或變基時移至次提交)。
敗則:若續命敗,察 git status 之未解文。諸衝必解後方可續。
若解過繁或擇誤徑,安棄之:
# Abort merge
git merge --abort
# Abort rebase
git rebase --abort
# Abort cherry-pick
git cherry-pick --abort
得:庫返操始前之態。無數失。
敗則:若棄敗(罕),察 git reflog 尋操前提交而以 git reset --hard <commit> 復之。慎用——其棄未提之變。
操畢後:
# Verify clean working tree
git status
# Check that the merge/rebase result is correct
git log --oneline -5
git diff HEAD~1
# Run tests to confirm nothing is broken
# (language-specific: devtools::test(), npm test, cargo test, etc.)
得:淨工作樹、正合史、試過。
敗則:若解後試敗,合或致邏輯誤雖法衝已解。詳審差而修。
<<<<<<<、=======、>>>>>>>)留於任何文git status 示淨工作樹git log 中合/變基之史正--ours 或 --theirs 全棄他側。獨於確一版全正時用之--amend 除非變基步明請。代以 git rebase --continuegit rebase --abort 與 git merge --abort 棄諸解之勞。獨於欲重始時棄之commit-changes — 解衝後之提交manage-git-branches — 致衝之枝流configure-git-repository — 庫之設與合策