快速解决git am冲突

前言

当希望通过git am xxxx.patch,添加一些代码修改,如果代码版本相差较大,就可能产生冲突。

这种必须要我们手动修改冲突内容。

解决过程

1. git am 尝试打入patch补丁

bash 复制代码
git am 0004-patch.patch

2. git apply --reject生成冲突文件

执行此命令,将自动合入 patch 中不冲突的代码改动,同时保留冲突的部分。这些存在冲突的改动内容会被单独存储到目标源文件的相应目录下,以后缀为 .rej 的文件进行保存。

bash 复制代码
git apply --reject 0004-patch.patch

3. git status查看冲突文件

bash 复制代码
git status

4. 解决冲突

打开xxx.rej文件,例如这里的virtio-gpu.h.rej

其中包含了冲突内容,进入到对应的源码文件中,将冲突部分手动改进去就可以了。
改完后,将对应的.rej文件删除掉。

bash 复制代码
# 查看
git status

5. git add xxx

将解决的冲突修改,添加到暂存区

bash 复制代码
git add include/hw/virtio/virtio-gpu.h

6. git am --resolved

bash 复制代码
git  am  --resolved

继续完成,1中被中断的 patch 合入操作。

如下图所示,applying:xxx,表示成功将该patch完整的加入到了项目代码中


参考文章

1. 定位和解决git am冲突的方法

相关推荐
司徒小夜5 小时前
处理git没做修改,但是文件显示变更的情况
git
m0_749317527 小时前
vscode里如何用git
ide·git·vscode
Hello.Reader7 小时前
Git 安装全攻略Linux、macOS、Windows 与源码编译
linux·git·macos
王景程8 小时前
SELinux是什么以及如何编写SELinux策略
git·github
Chuncheng's blog8 小时前
如何基于Mihomo Party http端口配置git与bash命令行代理
git·http·bash
Tom Boom8 小时前
Git常用命令完全指南:从入门到精通
大数据·git·elasticsearch·docker·自动化测试框架
不爱学英文的码字机器10 小时前
[Git] 文件删除
git
DZSpace11 小时前
git stash命令用法
git
Vowwwwwww11 小时前
GIT历史存在大文件的解决办法
前端·git·后端
@BreCaspian12 小时前
Git 推送失败解决教程——error: failed to push some refs to
大数据·git·elasticsearch