views:

70

answers:

3

How can I get "git add -i" to start up in patch mode directly without having to type "5" + Enter?

I know about "git add -p", but it's not the same as it doesn't show me a list of files to select from first.

This is very annoying because I'd like to jump between "git add -i" and "git commit" very quickly to turn my dirty tree into some nice looking commits.

+1  A: 

What you could do, is 'git add -p' and add the filenames as commandline arguments. with good tab completion (which only completes dirty files) it's about as effective as picking them from the menu.

Dieter_be
I have tab completion for git, but it doesn't seem to only give me dirty files on git 'add -p'.Otherwise this might be a viable alternative. I'd still like to use the git add -i interface so ...
felixge
`git add -p` with no arguments already automatically assumes you want to add patchwise all of the modified files. Not really much gain this way...
Jefromi
+1  A: 

It's a fairly easy change on a perl file to make this happen. I would only recommend doing this if you don't like the default git-add -p behavior of patching all files.

Find your copy of git-add--interactive and open with your favorite editor. Go to the patch_update_cmd subroutine. In there, there is an if statement which tests $patch_mode. Remove the top part of the if statement or set it so that the conditional always evaluates to false. Save and test.

An example of what I did to make this work follows.

if (0) {
  @them = @mods;
}
else {
  @them = list_and_choose({ PROMPT => 'Patch update',
          HEADER => $status_head, },
        @mods);
}

Another possible point of change would be at the very bottom of the file. You can change $patch_mode to some false value after the if statement, the effect should be the same.

Note you may have some issues if you're using a package manager or something else similar which tracks installed packages, I'm not sure.

deterb
Thanks, I'll give that a try once I have some more time. If I do this I'll talk to the maintainers to see if it could be merged upstream before. I'm not interested in maintaining my own git fork : )
felixge
A: 

If you don't mind bringing up a gui, just use git gui.

deterb