【发布时间】:2019-09-04 21:12:55
【问题描述】:
假设我有两个相似的存储库 A 和 B,但提交历史不同。
一个例子可能是两个 Python Flask 应用程序,或者两个 Ruby on Rails 应用程序,它们共享 很多 个相似文件,但并不完全相同。
我对存储库 A 进行了更改,我想也将其应用于存储库 B。将其应用于 B 可能会有一些冲突,但没关系,我想看看它们是什么并解决他们。
我尝试了以下从 repo A 生成补丁
> cd ~/git/repoA/
> git format-patch HEAD~
0001-My-Example-Commit.patch
> mv 0001-My-Example-Commit.patch ~/git/repoB
然后我尝试将补丁应用到 repo 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"
....
【问题讨论】: