我对仓库 A 做了一些更改,现在我也想将这些更改应用到仓库 B 中。在将更改应用到 B 时可能会遇到一些冲突,但没关系,我想看看这些冲突并逐个解决。
我尝试了以下步骤来从仓库 A 生成补丁:
> cd ~/git/repoA/
> git format-patch HEAD~
0001-My-Example-Commit.patch
> mv 0001-My-Example-Commit.patch ~/git/repoB
然后我试着将补丁应用到B仓库
> cd ~/git/repoB
> git am 0001-My-Example-Commit.patch
Applying: My Example Commit
error: patch failed: Gemfile:20
error: Gemfile: patch does not apply
error: patch failed: Gemfile.lock:125
error: Gemfile.lock: patch does not apply
error: patch failed: app/assets/stylesheets/application.scss:29
error: app/assets/stylesheets/application.scss: patch does not apply
....
....
error: patch failed: spec/views/application/_mobile_navigation.html.erb_spec.rb:44
error: spec/views/application/_mobile_navigation.html.erb_spec.rb: patch does not apply
Patch failed at 0001 Using Devise for authentication
hint: Use 'git am --show-current-patch' to see the failed 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 status
On branch test-git-apply
You are in the middle of an am session.
(fix conflicts and then run "git am --continue")
(use "git am --skip" to skip this patch)
(use "git am --abort" to restore the original branch)
nothing to commit, working tree clean
Git不会将更改应用为差异,因此没有差异/修改的文件,我甚至无法看到冲突是什么或尝试解决它们。
有没有一种方法可以强制git显示冲突?
谢谢!
编辑:
我知道--directory
选项存在,但我认为它在这里并不适用,因为我的补丁文件已经相对于同一根目录生成了。例如:
diff --git a/Gemfile b/Gemfile
index c970c34..ffc812d 100644
--- a/Gemfile
+++ b/Gemfile
@@ -20,12 +20,17 @@ gem "webpacker", "~> 3.5", ">= 3.5.5"
#
gem "bcrypt", "~> 3.1", ">= 3.1.10"
gem "cancancan", "~> 3.0"
....
>>>>>>
和<<<<<<
)冲突。而我作为作者,则需要手动接受其中之一。尽管如此,感谢您的见解,谢谢! - user2490003index
行包含原始文件的哈希 ID,Git 可以使用某些 Git 补丁来完成此操作。 - torekgit apply --3way
或git am --3way
,Git 将尝试执行此操作。如果您使用git format-patch
生成补丁,则它们将具有索引行(并且您可以使用--full-index
来防止可能使它们模糊不清的缩写),但是这些行可能不对应于存储库中的实际 blob。 - torekgit fetch
获取A的提交,然后运行git cherry-pick
。这种策略将执行三方合并并提供所需的冲突行。 - torek