Git分支合并操作指南
1. 合并分支到主分支
git checkout develop # 切换到主分支
git merge feature-branch # 合并功能分支
2. 解决合并冲突
# 查看冲突文件
git status
# 编辑冲突文件,删除冲突标记:
# <<<<<<< HEAD
# =======
# >>>>>>> branch-name
# 标记冲突已解决
git add conflicted-file.txt
# 完成合并
git commit
冲突标记 - 必须完全删除 <<<<<<<
、=======
、>>>>>>>
标记
3. 取消合并
git merge --abort # 取消当前合并操作
4. 快捷操作
快速解决冲突
git checkout --ours file # 使用当前分支版本
git checkout --theirs file # 使用合并分支版本
git add file && git commit # 提交解决方案
一键推送设置跟踪
# 已经提交过并设置过上游分支
git push
# 未设置上游分支
git push origin $(git branch --show-current)
# 新分支,提交并设置上游分支
git push -u origin $(git branch --show-current)