gitgit-diffinteractive-mode

Some choices in interactive mode don't work on git


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 ask again for a choice.

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

Is there a reason for that?


Solution

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

    git only gives you the choices y,n,q,a,d,/,s,e,?, because the file's snapshot only has 1 hunk. The help prints out all options that might be available, but in your case you don't have the option to skip a hunk.

    A hunk is one diff in a file. So what git wants to tell you is that there is only one diff in that file. So you can not skip it and go to the next one.

    For example.. if I create a text file and put your question in it so that I will get this diff

    @@ -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.
    

    Than an interactive checkout would let me split the actual hunk into smaller hunks.

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

    After that you can select which hunk to apply and which to skip.

        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
    

    Skip (j) and go on to the next hunk.

    @@ -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,?]?