Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 删除线时应如何编辑修补程序签出?_Git_Bash_Patch - Fatal编程技术网

Git 删除线时应如何编辑修补程序签出?

Git 删除线时应如何编辑修补程序签出?,git,bash,patch,Git,Bash,Patch,我有一个文件bar.txt,其中我删除了3行,但还没有发布任何内容。我想通过git checkout-p还原删除的一行 示例/Bash输出: $ git checkout -p foo/bar.txt diff --git a/bin/custom/foo/bar.txt b/bin/custom/foo/bar.txt index 35483b7..e945cae 100644 --- a/bin/custom/foo/bar.txt +++ b/bin/custom/foo/bar.txt

我有一个文件
bar.txt
,其中我删除了3行,但还没有发布任何内容。我想通过
git checkout-p
还原删除的一行

示例/Bash输出:

$ git checkout -p foo/bar.txt
diff --git a/bin/custom/foo/bar.txt b/bin/custom/foo/bar.txt
index 35483b7..e945cae 100644
--- a/bin/custom/foo/bar.txt
+++ b/bin/custom/foo/bar.txt
@@ -1097,9 +1097,6 @@ mond.desc.refinements   = Foo
 mond.desc.removeAttribute                    = Foo
 mond.desc.resultsForStore                    = Foo
 mond.no.results                              = Foo
-mond.page.CO.class.name                      = Foo
-mond.page.CO.parent.name                     = Foo
-mond.page.brands.parent.name                 = Foo
 mond.page.cmscontent.datetime                = Foo
 mond.page.currentPage                        = Foo
 mond.page.firstPage                          = Foo
我试过这样的方法:

@@ -1097,9 +1097,8 @@ mond.desc.refinements   = Foo
 mond.desc.removeAttribute                    = Foo
 mond.desc.resultsForStore                    = Foo
 mond.no.results                              = Foo
-mond.page.CO.class.name                      = Foo
 mond.page.CO.parent.name                     = Foo
 mond.page.brands.parent.name                 = Foo
 mond.page.cmscontent.datetime                = Foo
 mond.page.currentPage                        = Foo
 mond.page.firstPage                          = Foo

但它不起作用。

我可能会朝另一个方向去做。在
git中添加-p
您想要的更改,提交它们,然后
git签出,这样就不会太费心了。
可以清除其他内容。如果您实际上还不想提交,只需
git reset HEAD ^
撤消我们刚才所做的提交,将保留的更改保留在您的工作区中

但这不是你要的,也不是那么有趣,所以


这让人困惑,因为双重否定并不让人困惑,但是如果你把你的大脑向右转,你就可以控制它

假设我们有文件
编号
,包含:

one
two
three
four
我们删除了
2个
3个
,因此
git diff
看起来像:

diff --git a/numbers b/numbers
index f384549..a9c7698 100644
--- a/numbers
+++ b/numbers
@@ -1,4 +1,2 @@
 one
-two
-three
 four
现在我们运行
git checkout-p number
。请注意,提示询问您是否要丢弃减去
2
3
的大块头。如果您说
y
,它将放弃减法运算,留下一个包含所有四个数字的完整文件

 one
-two
-three
 four
Discard this hunk from worktree [y,n,q,a,d,/,e,?]?
所以现在我们将编辑这个大块头来创建我们想要丢弃的大块头。这意味着,如果我们实际上只想删除
2个
,我们就要放弃删除
3个
的更改。与直觉相反,这意味着您可以通过删除
-two
来编辑帅哥

这将放弃删除
三个
,而不会放弃删除
两个
,这将给我们留下差异:

diff --git a/numbers b/numbers
index f384549..ceb5927 100644
--- a/numbers
+++ b/numbers
@@ -1,4 +1,3 @@
 one
-two
 three
 four

总之,删除你仍然想删除的那一行。保留要放弃的减法行。您编辑的大块将包含您保留的行的减法(将被丢弃),而不包含您仍要删除的行。

您所说的实际上是有意义的,但我无法复制它。也许这是因为我使用Cygwin而不是“真正的”UNIX系统。我会试着弄到一个,试试看。我读了你的解释,非常感谢,这里有一个我可以使用的概要;DR:编辑修补程序时,将其更改为应用所有要保留的更改(删除
-
行,将
+
行更改为空格),并保留要放弃的更改(
-
+
行)。
diff --git a/numbers b/numbers
index f384549..ceb5927 100644
--- a/numbers
+++ b/numbers
@@ -1,4 +1,3 @@
 one
-two
 three
 four