我正在尝试使用 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
加入。