最佳答案
我正在尝试使用 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
给出了如上所示的第一个错误: “ error: patch false: index.php: 17”,但是没有在 index.php
中添加冲突标记。