git 文件冲突之后如何操作

冲突报错

bash 复制代码
git status
interactive rebase in progress; onto f1def41fc
Last command done (1 command done):
   pick 0d2ff5c91 deploy tju
No commands remaining.
You are currently rebasing branch 'zld' on 'f1def41fc'.
  (fix conflicts and then run "git rebase --continue")
  (use "git rebase --skip" to skip this patch)
  (use "git rebase --abort" to check out the original branch)

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
......

Unmerged paths:
  (use "git restore --staged <file>..." to unstage)
  (use "git add <file>..." to mark resolution)
	both modified:   xxx(dir/filename)

解决

你当前正在 git rebase 的过程中,提示信息显示:

  • 上一次的命令已经执行完(pick 0d2ff5c91 deploy tju)。
  • 当前还有冲突未解决:ansible/inventory/tju 文件显示 both modified,也就是在你的分支和被 rebase 的目标分支上都有修改。

正确操作步骤如下:

  1. 查看冲突内容
bash 复制代码
git diff ansible/inventory/tju

你会看到类似下面的标记:

复制代码
<<<<<<< HEAD
你的修改内容
=======
目标分支的修改内容
>>>>>>> f1def41fc

需要手动选择保留哪一部分,或者合并两边内容。

  1. 标记冲突解决完成

编辑完文件后,保存,然后执行:

bash 复制代码
git add ansible/inventory/tju
  1. 继续 rebase
bash 复制代码
git rebase --continue

如果还有其他冲突,重复步骤 1~3。

  1. 可选操作
  • 如果你决定不保留当前 commit,可以跳过:
bash 复制代码
git rebase --skip
  • 如果想放弃 rebase,回到最初分支状态:
bash 复制代码
git rebase --abort

⚠️ 提示 :当前状态下,Changes to be committed 已经列出了你新增/修改的文件,但 冲突文件必须先解决并 git add ,否则 --continue 会报错。

如果你需要,我可以帮你写一个 快速合并 ansible/inventory/tju 冲突的模板,直接保留两边或者选一个版本。你希望怎么处理冲突?

相关推荐
是宇写的啊14 小时前
Git远程操作
git
our_times1 天前
# Git 高频命令实战指南:从日常开发到进阶协作
git
PBitW1 天前
git 中容易遗忘的点 (二) ⚡⚡⚡
前端·git·面试
PBitW1 天前
git 中容易遗忘的点 (三) 🚀🚀🚀
前端·git·面试
郑州光合科技余经理1 天前
家政预约小程序后端源码深度剖析:支付回调实战
java·开发语言·前端·git·小程序·架构·php
北极糊的狐1 天前
钉钉小程序 Git 版本管理完整流程
git·小程序·钉钉
Fzuim2 天前
当 AI 也成为提交者:ThinkFlow 的 Git 提交规范,是怎么定的
git·agent·thinkflow
CodexDave2 天前
数据库连接池耗尽:排查顺序与三层兜底
服务器·前端·数据库·git·云原生·容器·kubernetes
乐观的Terry2 天前
5、发布系统-Git 集成
大数据·git·elasticsearch
不怕犯错,就怕不做2 天前
GIT的简单打patch应用format-patch and git am
linux·git·全文检索