我有一个文件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但不起作用。
发布于 2016-04-04 17:54:48
我可能会朝另一个方向去做。这是更少的思想扭曲git add -p你想要的变化,提交他们,然后git checkout .清除其他的东西。如果您还不想提交,那么只需要git reset HEAD^来撤消我们刚刚完成的提交,将保留的更改留在您的工作区中。
但这不是你想要的,也没那么有趣,所以.
这让人困惑,因为双重否定并不会让人感到困惑,但如果你把大脑向右弯曲,你就能做到这一点。
假设我们有文件numbers,包含:
one
two
three
four我们删除two和three,因此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 numbers。注意,提示询问是否要丢弃减去two和three的块。如果您说y,它就放弃减法,留下一个包含所有四个数字的完整文件。
one
-two
-three
four
Discard this hunk from worktree [y,n,q,a,d,/,e,?]?所以,现在我们将编辑hunk来创建我们想要丢弃的块。这意味着如果我们实际上只想删除two,那么我们希望放弃删除three的更改。与直觉相反,这意味着您通过删除-two来编辑hunk。
@@ -1,4 +1,2 @@
one
-three
four这就放弃了three的删除,而不放弃two的删除,留给我们的是差异:
diff --git a/numbers b/numbers
index f384549..ceb5927 100644
--- a/numbers
+++ b/numbers
@@ -1,4 +1,3 @@
one
-two
three
four因此,概括地说,删除你仍然想要删除的行。留下你想要丢弃的减法线。您所编辑的块将包含对您保留的行的减法(将被丢弃),而不会包含您仍然想要删除的行。
https://stackoverflow.com/questions/36406954
复制相似问题