Mỗi [y, n, q, a, d, /, K, j, J, g, e ,?] đại diện cho cái gì trong ngữ cảnh của git -p


272

Khi sử dụng chế độ -p của git add -phoặc git stash -pmỗi chữ cái có nghĩa là gì?

Tôi đoán ylà có và nkhông. Phần còn lại là gì?

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


64
Nếu bạn thử ?tùy chọn này, bạn sẽ tìm ra
Abe Voelker

7
Có lẽ bạn chỉ cần cuộn lên một chút?
Cosimo

1
Bản in trong câu trả lời được chấp nhận bao gồm các tùy chọn không được liệt kê khi nhập '?'
Đánh dấu

Câu trả lời:


325

Các -pbản vá chế độ phương tiện, sự giúp đỡ mà khó-ish để tìm, nhưng nếu bạn kiểm tra git add --helpbạn sẽ tìm thấy những điều sau đây

   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 sẽ tiến hành tập tin tiếp theo trong khi q sẽ hủy bỏ hoàn toàn quy trình?
Steve

5
qkhông không thiết lập lại bất kỳ thay đổi dàn dựng trước đó. Bất cứ điều gì bạn đã dàn dựng vẫn được dàn dựng.
Alexander Bird

Tôi sử dụng -pđể đâm, không biết bạn cũng có thể sử dụng cái này add! Chỉ cần thêm vào câu trả lời này, trong khi có đề cập đến -p | --patchcờ, cmd này: git stash --helpKHÔNG cung cấp cho bạn thông tin tương tự về các tùy chọn vá như git add --helphiện tại.
Phil Gibbins

31

Ý nghĩa của những chữ cái này có thể được tìm thấy bằng cách gõ ? và nhấn phím Enter . Đối với tôi những điều này đã không đến khi chạy git add --help. Tôi hiểu ý nghĩa của các tùy chọn này như sau: -

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,?]? 
Khi sử dụng trang web của chúng tôi, bạn xác nhận rằng bạn đã đọc và hiểu Chính sách cookieChính sách bảo mật của chúng tôi.
Licensed under cc by-sa 3.0 with attribution required.