【发布时间】:2014-11-08 20:52:52
【问题描述】:
我正在尝试使用 git 将多个提交从一个项目移动到第二个类似的项目。
所以我创建了一个补丁,包含 5 个提交:
git format-patch 4af51 --stdout > changes.patch
然后将补丁移动到第二个项目的文件夹并要应用补丁:
git am changes.patch
...但它给了我错误:
Applying: Fixed products ordering in order summary.
error: patch failed: index.php:17
error: index.php: patch does not apply
Patch failed at 0001 Fixed products ordering in order summary.
The copy of the patch that failed is found in:
c:/.../project2/.git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
所以我打开了 index.php,但那里没有任何变化。我假设有一些>>>>>>> 标记等,例如在解决合并冲突时,但文件中没有标记冲突。 git status 还给了我更改文件的空列表(只有 changes.patch 在那里)。于是我跑了git am --continue,但是又出现了一个错误:
Applying: Fixed products ordering in order summary.
No changes - did you forget to use 'git add'?
If there is nothing left to stage, chances are that something else
already introduced the same changes; you might want to skip this patch.
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
我使用的是 Windows 7 和最新的 git 版本“1.9.4.msysgit.1”
附:经过几个小时的谷歌搜索,我找到了一些解决方案,但对我来说没有任何效果:
git am -3 changes.patch
给出奇怪的“sha1 信息”错误:
Applying: Fixed products ordering in order summary.
fatal: sha1 information is lacking or useless (index.php).
Repository lacks necessary blobs to fall back on 3-way merge.
Cannot fall back to three-way merge.
Patch failed at 0001 Fixed products ordering in order summary.
The copy of the patch that failed is found in:
c:/.../project2/.git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
git am changes.patch --ignore-whitespace --no-scissors --ignore-space-change
如上给出第一个错误:“错误:补丁失败:index.php:17”,但在index.php 中没有添加冲突标记。
【问题讨论】:
-
我也一直在为此苦苦挣扎。但在某些情况下,它是由在 CRLF 处于行尾时提交的文件(来自例如 WINdows 源)引起的。尽管有像 eol.crlf 这样的配置功能,git 似乎不喜欢 CRLF 行结尾。关于 cr/lf 问题的示例链接:stackoverflow.com/questions/1510798/…
-
太棒了。只需将我收到的补丁的行尾转换为“Unix”风格,然后它就可以工作了。这赢得了支持。
标签: git