在git -p的上下文中,每个[y,n,q,a,d,/,K,j,J,g,e ,?]代表什么?


272

使用-p模式时,git add -pgit stash -p每个字母代表什么?

我猜y是肯定的,n不是。剩下的是什么?

[y,n,q,a,d,/,K,j,J,g,e ,?]


64
如果您尝试使用该?选项,则会发现
安倍·沃克

7
也许您只需要向上滚动一点即可?
2013年

1
接受的答案中的打印输出包括输入“?”时未列出的选项。
标记

Answers:


325

-p模式意味着补丁,很难找到其帮助,但是如果您进行检查git add --help,将会发现以下内容

   patch
       This lets you choose one path out of a status like selection. After choosing the path, it presents the diff between the index and the working tree file and asks you if you want to stage the change of each hunk. You can select one of the following options and type return:

           y - stage this hunk
           n - do not stage this hunk
           q - quit; do not stage this hunk nor any of the remaining ones
           a - stage this hunk and all later hunks in the file
           d - do not stage 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

8
@VicGoldfeld d将继续处理下一个文件,而q会完全中止该过程吗?
史蒂夫(Steve)

5
q没有重置任何以前上演的变化。无论您已经上演过什么,都将继续上演。
亚历山大·伯德

-p用于存储,不知道您也可以使用它add!只是为了增加此答案,尽管提到了该-p | --patch标志,但此cmd:git stash --help与补丁选项有关的信息git add --help并不相同。
Phil Gibbins

31

这些字母的含义可以通过键入找到然后按Enter键。对我来说,这些并没有在跑步时出现git add --help。我得到这些选项的含义如下:

Arup-iMac:$ git add -p
diff --git a/app/interactors/reporting_groups/list_colleagues.rb b/app/interactors/reporting_groups/list_colleagues.rb
index adc28af..f46f5e3 100644
--- a/app/interactors/reporting_groups/list_colleagues.rb
+++ b/app/interactors/reporting_groups/list_colleagues.rb
@@ -14,7 +14,4 @@ module ReportingGroups
         reporting_group.employees_from_team_sub_reporting_groups
       else
         reporting_group.users
-      end
-    end
-  end
-end
+      
Stage this hunk [y,n,q,a,d,/,e,?]? ? <-- Look here, what I typed to get these.
y - stage this hunk
n - do not stage this hunk
q - quit; do not stage this hunk nor any of the remaining ones
a - stage this hunk and all later hunks in the file
d - do not stage 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
@@ -14,7 +14,4 @@ module ReportingGroups
         reporting_group.employees_from_team_sub_reporting_groups
       else
         reporting_group.users
-      end
-    end
-  end
-end
+      
Stage this hunk [y,n,q,a,d,/,e,?]? 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.