具有多次提交的Git补丁,并且最后一次未应用

问题描述 投票:0回答:1

我有2个存储库,正在尝试使用补丁程序将更改从一个移动到另一个。以下是方案。有一个提交(f31541e)更改3个文件的内容。然后,最后一次提交(日志的顶部,b546664)删除其中一个文件c.txt。

$ git log                                                                       
**commit b54666405a5126e6efcb8b605b3bb0182200f258** (HEAD -> develop, origin/develop
)                                                                               
Author: Andy Whelan                                         
Date:   Tue Feb 25 12:31:24 2020 -0500                                                                                                                 
    Deleted c.txt                                     
**commit f31541e1b6f417deab23e38bab25f854ac45ade6** (origin/patch-delete-c, origin/p
atch-branch-src-us1, patch-delete-c, patch-branch-src-us1)                      
Author: Andy Whelan                                         
Date:   Tue Feb 25 11:00:49 2020 -0500                                                         
    Modified all 3 files.                                          
**commit 32b12065cfa3aa25f07c2698197788792c55b99d** (origin/master, master)         
Author: Andy Whelan                                         
Date:   Tue Feb 25 08:39:54 2020 -0500                                          
    Adding a.txt, b.txt, c.txt                                                  

我正在创建单个补丁文件,如下所示:

git format-patch -2 b54666405a5126e6efcb8b605b3bb0182200f258 --stdout > can.patch

补丁文件(下面)的最新更改(已删除的文件)在底部,另一个在顶部。以下是此文件的一些内容,我注释掉了更改3个文件中的文本的部分,因为它可以工作(//内容更改了3个文件,这可以工作)。我遇到的麻烦是未删除c.txt ,应该是这样。将应用3个文件中的文本更改。但是文件删除不是。有人知道我可能在做什么错吗?

From f31541e1b6f417deab23e38bab25f854ac45ade6 Mon Sep 17 00:00:00 2001
From: Me <[email protected]>
Date: Tue, 25 Feb 2020 11:00:49 -0500
Subject: [PATCH 1/2] patch modifies all 3 files

---
//content changes 3 files, this works
-- 
2.20.1.windows.1


From b54666405a5126e6efcb8b605b3bb0182200f258 Mon Sep 17 00:00:00 2001
From: Me <[email protected]>
Date: Tue, 25 Feb 2020 12:31:24 -0500
Subject: [PATCH 2/2] applied patch-delete-c

---
 c.txt | 2 --
 1 file changed, 2 deletions(-)
 delete mode 100644 c.txt

diff --git a/c.txt b/c.txt
deleted file mode 100644
index 1a7ca5c..0000000
--- a/c.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-this is file c
-add a line to c
\ No newline at end of file
-- 
2.20.1.windows.1
git
1个回答
0
投票

[参见上面有关使用的torek的评论

git am <patchfilename>

这是正确的答案。

© www.soinside.com 2019 - 2024. All rights reserved.