2

我只是在尝试使用提交结帐的交互模式

git checkout -p <commit_sha1>

有不同的选择可供选择

将此块应用于索引和工作树 [y,n,q,a,d,/,s,e,?]?

并按下?它会显示更多选项

y - 将此块应用于索引和工作树
n - 不要将此块应用于索引和工作树
q - 退出;不要应用这个大块或任何剩余的
a - 在文件中应用这个大块和所有后来的大块
d - 不要应用这个大块或文件中的任何后续大块
g - 选择一个大块去
/ - 搜索匹配给定正则表达式的块
j - 让这个大块未定,见下一个未定大块
J - 留下这个大块未定,看下一个大块
k - 让这个大块未定,查看之前未定的大块
K - 留下这个大块未定,看以前的大块
s - 将当前的大块分割成更小的块
e - 手动编辑当前块
? - 打印帮助

我实际上尝试了所有未决定的帅哥的亲戚,但他们似乎都没有工作。选择后,无论我按j/J/k/K还是s,它总是返回到同一个文件并再次要求选择。

而所有其他(y/n/q/a/d/..等)都可以工作。

这有什么原因吗?

4

1 回答 1

4
Apply this hunk to index and worktree [y,n,q,a,d,/,s,e,?]?

git 只给你选择y,n,q,a,d,/,s,e,?,因为文件的快照只有 1 块。帮助会打印出所有可能可用的选项,但在您的情况下,您无法选择跳过大块。

大块是文件中的一个差异。所以 git 想告诉你的是那个文件中只有一个差异。所以你不能跳过它并转到下一个。

例如..如果我创建一个文本文件并将您的问题放入其中,以便获得此差异

@@ -1,9 +1,28 @@
 I'm just trying the interactive mode with a commit checkout

+    git checkout -p <commit_sha1>
+
 There are different choices available

+    Apply this hunk to index and worktree [y,n,q,a,d,/,s,e,?]?
+
 and pressing ? it shows even more options

+    y - apply this hunk to index and worktree
+    n - do not apply this hunk to index and worktree
+    q - quit; do not apply this hunk nor any of the remaining ones
+    a - apply this hunk and all later hunks in the file
+    d - do not apply this hunk nor any of the later hunks in the file
+    g - select a hunk to go to
+    / - search for a hunk matching the given regex
+    j - leave this hunk undecided, see next undecided hunk
+    J - leave this hunk undecided, see next hunk
+    k - leave this hunk undecided, see previous undecided hunk
+    K - leave this hunk undecided, see previous hunk
+    s - split the current hunk into smaller hunks
+    e - manually edit the current hunk
+    ? - print help
+
 I actually tried all the relatives to undecided hunks, and none of them seem to work. After the choice, no matter if I press j/J/k/K or s it always returns to the same file and as
k again for a choice.

 While all the others (y/n/q/a/d/.. etc.) work.

比起交互式结账,我可以将实际的大块分成更小的块。

Apply this hunk to index and worktree [y,n,q,a,d,/,s,e,?]? s

之后,您可以选择要应用哪个块以及要跳过哪个块。

    Split into 3 hunks.
@@ -1,4 +1,6 @@
 I'm just trying the interactive mode with a commit checkout

+    git checkout -p <commit_sha1>
+
 There are different choices available

Apply this hunk to index and worktree [y,n,q,a,d,/,j,J,g,e,?]? j

跳过 ( j) 并继续下一个大块。

@@ -3,4 +5,6 @@
 There are different choices available

+    Apply this hunk to index and worktree [y,n,q,a,d,/,s,e,?]?
+
 and pressing ? it shows even more options

Apply this hunk to index and worktree [y,n,q,a,d,/,k,K,j,J,g,e,?]?
于 2014-10-02T08:59:42.307 回答