git apply failed (转载)
转自:http://blog.csdn.net/aaronzzq/article/details/6955893
git version 1.6.0.4
几个新手刚刚开始接触 Git,为了维护核心仓库的“纯洁”,避免太多无关信息被误提交进仓库(再次批评一些图形化工具默认的“Select All”),采用了核心仓库只读,邮件提交 patch,审核后再提交的工作流程。
期间有时会遇到合并冲突,正常的原因一般是未及时下载新版本产生了冲突,特殊一点的原因是手工修改 patch 内容导致的。有时候看注释写得不够准确,忍不住就改了,有时候是 Geany 保存时自动去除了 patch 原文中的行尾空格,有时候是文件回车格式、BOM 等变动了,总之合并 patch 的时候,如果生成 patch 的“原稿”找不到,一般就产生了冲突,比如:
$ git am 0001-BUG-Sybase.patch
Applying: CHG: 读取Sybase如果时间为空,设置默认时间的修改
error: patch failed: source.php:38
error: source.php: patch does not apply
Patch failed at 0001.
When you have resolved this problem run "git am --resolved".
If you would prefer to skip this patch, instead run "git am --skip".
To restore the original branch and stop patching run "git am --abort".
刚开始一看有些懵,因为没有任何冲突在哪里的提示,后来找到一种方法,am 操作出问题后先手工 apply:
$ git apply --reject 0001-BUG-Sybase.patch
Checking patch source.php...
error: while searching for:
// 注释
// 以下为几行代码片断
error: patch failed: source.php:38
Applying patch source.php with 1 rejects...
Rejected hunk #1.
这样,就把没有冲突的文件先合并了,剩下有冲突的作了标记。先看输出,error: while searching for: 说明是这段代码有冲突,error: patch failed: source.php:38 指明了产生冲突的代码片断的开始行号,相应的,patch 中应该有这么一段:
diff --git a/source.php b/source.php
index 8770441..4e77b8a 100644
--- a/source.php
+++ b/source.php
@@ -38,27 +38,23 @@ class Site extends Module
// 注释
// 以下为几行代码片断
同时,还会产生一个 source.php.rej 文件,里面也是上面这段因为冲突无法合并的代码片断。
现在,在这段代码中查找冲突原因,并对文件进行修改,source.php.rej 参考完了可以删掉。改好之后,用 git add 把 source.php 添加到缓冲区,同时也要把其他没有冲突合并成功了的文件也加进来,因为在作 apply 操作的时候他们也发生了变化:
$ git add source.php
$ git add 其他 apply 进来的文件们
最后:
$ git am --resolved
Applying: CHG: 读取Sybase如果时间为空,设置默认时间的修改
大功告成。
中间如果处理乱了,用 git reset 恢复即可,所以合并 patch 在一个“干净”的分支上处理更好。
git apply failed (转载)的更多相关文章
- git apply、git am打补丁.diff 和 .patch【转】
本文转载自:https://www.jianshu.com/p/e5d801b936b6 前提: 生成patch: git format-patch -M master 生成指定patch,0163b ...
- git diff 生成patch, git apply patch 打补丁方法说明,以及分支管理的简单操作。
git diff 简易操作说明 先git log 查看commit ID, 记录你想要打的补丁的ID 比如说: git log commit 4ff35d800fa62123a28b7bda2a04e ...
- git format-patch & git apply & git clean
一.打补丁 git format-patch & git apply 最近在工作中遇到打补丁的需求,一来觉得直接传文件有些low(而且我尝试了一下,差点把项目代码毁了) ,二来也是想学习一下, ...
- 深入浅出Git教程【转载】转载
深入浅出Git教程(转载) 目录 一.版本控制概要 1.1.什么是版本控制 1.2.常用术语 1.3.常见的版本控制器 1.4.版本控制分类 1.4.1.本地版本控制 1.4.2.集中版本控制 1 ...
- IDEA : Git Pull Failed 解决(IDEA中使用stash功能)
一.问题: 本地要commit代码,commit之前需pull代码,但pull提示冲突.如下 Git Pull Failed Your local changes would be overwritt ...
- git & github & git clone & 'git clone' failed with status 128
git & github & git clone & 'git clone' failed with status 128 'git clone' failed with st ...
- git schnnel failed to receive handshake, SSLTLS connection failed
git schnnel failed to receive handshake, SSLTLS connection failed 报错,查看原因为git安装时ssl选择的不是openssl.重新安装 ...
- Git使用教程(转载)
Git使用教程 一:Git是什么? Git是目前世界上最先进的分布式版本控制系统. 二:SVN与Git的最主要的区别? SVN是集中式版本控制系统,版本库是集中放在中央服务器的,而干活的时候,用的都是 ...
- git cherry-pick简介(转载)
转自:http://hubingforever.blog.163.com/blog/static/1710405792012587115533/ 本文编辑整理自: http://sg552.iteye ...
随机推荐
- pyv8的安装和使用:python中执行js代码
pyv8 的作用是在python中执行js代码,然后可以使用js里的变量等内容.python取得javascript里面的值.javascript取得python里面的值.python和javascr ...
- svm、logistic regression对比
相同点:都是线性分类算法 不同点: 1.损失函数不同 LR:基于“给定x和参数,y服从二项分布”的假设,由极大似然估计推导 SVM: hinge loss + L2 regularization的标准 ...
- [转】 nginx rewrite规则
http://www.cnblogs.com/cgli/archive/2011/05/16/2047920.html 最近在VPS上尝试配置安装一个网站,VPS安装了LNMP(Linux+Nginx ...
- 使用Python写的第一个网络爬虫程序
今天尝试使用python写一个网络爬虫代码,主要是想訪问某个站点,从中选取感兴趣的信息,并将信息依照一定的格式保存早Excel中. 此代码中主要使用到了python的以下几个功能,因为对python不 ...
- leetcode笔记:Contains Duplicate
一. 题目描写叙述 Given an array of integers, find if the array contains any duplicates. Your function shoul ...
- 重新认识一遍JavaScript
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Hadoop+HBase+ZooKeeper分布式集群环境搭建
一.环境说明 集群环境至少需要3个节点(也就是3台服务器设备):1个Master,2个Slave,节点之间局域网连接,可以相互ping通,下面举例说明,配置节点IP分配如下: Hostname IP ...
- Oracle db中禁止使用sqlplus的方法
先记录下来: How to Disable a SQL*Plus Connection for a User (文档 ID 124121.1)
- 【转载】关于Hash
这个HASH算法不是大学里数据结构课里那个HASH表的算法.这里的HASH算法是密码学的基础,比较常用的有MD5和SHA,最重要的两条性质,就是不可逆和无冲突.所谓不可逆,就是当你知道x的HASH值, ...
- yum lock
状态 :睡眠中,进程ID:18439Another app is currently holding the yum lock; waiting for it to exit... 另一个应用程序是: ...