交互模式中的一些选择不适用于git

时间:2014-10-02 08:34:21

标签: git git-diff interactive-mode

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

git checkout -p <commit_sha1>

有不同的选择

  

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

并按?它会显示更多选项

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

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

虽然所有其他人( y / n / q / a / d /..等)都有效。

这是否有原因?

1 个答案:

答案 0 :(得分:3)

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

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

hunk是文件中的一个差异。那么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,?]?