【Git】如何批量解决 Git Merge 产生的冲突
2024年1月29日大约 1 分钟约 440 字
壹。合并分支
# 检出 master 分支``→ git checkout master` `# 合并 feature 分支至 master 分支``→ git merge feature``Auto-merging Document``CONFLICT (content): Merge conflict ``in` `codefile.js``Automatic merge failed; fix conflicts and ``then` `commit the result.贰。解决冲突
如果文件少,或者需要改动的地方比较复杂,可手动解决冲突。如果仅想保留一方的改动,可使用以下命令
# to select the changes done in master``→ git checkout --ours codefile.js` `# to select the changes done in feature``→ git checkout --theirs codefile.js弎。继续合并
# 暂存区``→ git add codefile.js` `# then, continue as you would normally merge``→ git merge --``continue``[master 5d01884] Merge branch ``'feature'肆。批量解决冲突
在解决冲突的步骤,运行以下命令:
→ ``grep` `-lr ``'<<<<<<<'` `. | ``xargs` `git checkout --ours``# or``→ ``grep` `-lr ``'<<<<<<<'` `. | ``xargs` `git checkout --theirs