我正在尝试使用git将一个项目中的多个提交移动到第二个类似的项目中。
因此,我创建了一个包含5个提交的补丁:
git format-patch 4af51 --stdout > changes.patch
然后将补丁移动到第二个项目的文件夹中,并希望应用该补丁:
Then move the patch to second project's folder and wants to apply the 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 failed: index.php:17",但在index.php
中没有冲突标记。