Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the options of `git add -p`?

Tags:

git

git-add

Doing a git add -p I see a one diff and the list of choices :

~/workspace$ git add -p                                              
diff --git a/gulpfile.js b/gulpfile.js                                                 
index cf91028..c3a0964 100644                                                          
--- a/gulpfile.js                                                                      
+++ b/gulpfile.js                                                                      
@@ -57,7 +57,7 @@ gulp.task("pack", pack);                                             
 // Minify and concatenate all js libs                                                 
 gulp.task("libs", function() {                                                        
        return gulp.src([                                                              
-               "js/libs/trackjs.js",                                                  
+       //      "js/libs/trackjs.js",  // hidden due to noise but not the bug          
                "js/libs/q.js",                                                        
                "js/libs/jquery.js",                                                   
                "js/libs/cookie.js",                                                   
Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]?

What does Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]? options means ? Where to find their explanations ?

like image 615
Hugolpz Avatar asked Dec 30 '15 10:12

Hugolpz


1 Answers

If you type ? at the prompt, you get the explanation.

Specifically the options are:

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

In case you experience the same confusion as me, I found that sometimes the j,J,k,K options didn't work, I think (but haven't experimented enough to be certain) that they only work within the same file, so you can skip through hunks in the same file, but not skip on to the next file, then come back to the previous one.

like image 105
DaveyDaveDave Avatar answered Oct 21 '22 01:10

DaveyDaveDave