如果我从本地未提交的工作创建补丁 - 它会失败。如果我提交我的工作,然后创建补丁,它就会成功应用。为什么?

If I create a patch from local, uncommited work - it fails. If I commit my work, then create patch, it applies without fail. Why?

我想根据我的本地代码和远程源之间的差异创建一个补丁。

我这样做:

git diff origin/myTestBranch > myPatch.patch 

我进入一个单独的目录,该目录克隆了相同的存储库并且刚刚拉取了 myTestBranch。我这样做

cd testPatchRepo
git clone ....
git checkout myTestBranch

当我尝试应用补丁时 - 它失败了!

但是,如果我提交我的工作并创建一个补丁 git diff firstCommit ^...lastCommit > myPatch.patch 补丁应用没有问题.. .这并没有解决我的问题,因为我仍然希望能够从我本地未提交的工作中创建一个补丁。

这是根据本地未提交的工作创建的补丁:

 diff --git a/scripts b/scripts
index 8640468..adfabd7 160000
--- a/scripts
+++ b/scripts
@@ -1 +1 @@
-Subproject commit 8640468cc4ba87bebee0e9e26939361bcb3e3afa
+Subproject commit adfabd7bf11566f2888a4501bc557265f1172ac2-dirty
diff --git a/source/tutorial/install.txt b/source/tutorial/install.txt
index 5fee5f6..5ef6e4b 100644
--- a/source/tutorial/install.txt
+++ b/source/tutorial/install.txt
@@ -16,7 +16,7 @@ Install {+bi-short+} on Windows

 .. include:: /includes/fact-bi-enterprise.rst

-Massaddie
+Maaaaassaddie
 To set up |bi|,
 follow the steps on this page.

提交更改后创建的补丁:

commit 983393a03262f8dccfd90b3c948751846ae583ae
Author: maddie <myemail>
Date:   Mon Dec 2 17:17:42 2019 -0500

    commit before make stage commit

diff --git a/source/tutorial/install.txt b/source/tutorial/install.txt
index 5fee5f6..5ef6e4b 100644
--- a/source/tutorial/install.txt
+++ b/source/tutorial/install.txt
@@ -16,7 +16,7 @@ Install {+bi-short+} on Windows

 .. include:: /includes/fact-bi-enterprise.rst

-Massaddie
+Maaaaassaddie
 To set up |bi| with a business intelligence tool such as Tableau,
 follow the steps on this page.

虽然通常您可以将 git diff 的输出应用于另一个工作树,但在这种情况下您不能。原因是 git diff 表明你的子模块是脏的:也就是说,它有未提交的更改。由于无法在 diff 中按原样表示这些更改,因此任何应用它们的尝试都将失败。

如果你想排除这些子模块的变化,你可以使用git diff --ignore-submodules,这将忽略你的子模块,无论修改与否。如果你想递归地包含它们,你可以使用git diff --submodule=diff。该补丁不会更新子模块提交本身,但它会更改子模块工作树,因此不推荐。

这两个都应该产生适用的补丁。