Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jump to 'git add -i' patch command (5) directly

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.

like image 494
Felix Geisendörfer Avatar asked Apr 15 '26 16:04

Felix Geisendörfer


2 Answers

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.

like image 85
deterb Avatar answered Apr 17 '26 09:04

deterb


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.

like image 41
Dieter_be Avatar answered Apr 17 '26 09:04

Dieter_be