1

Is there a way in Git on the command line, or in a Git-GUI supported by Linux, to do git add -p for ONLY hunks that meet the two following conditions?

  1. the hunk involves changes of 50+ lines.
  2. the changes are only additions; no deletions

OR

How do I sort the hunks by their size?

Either option would help me achieve my goal:

I am merging two git branches, and my goal is to only look at the big hunks in one of the branches and decide whether to merge them or not. I don't want to use any of the hunks that don't meet the two above conditions, but be able to choose which hunks I add that do meet these two conditions.

I saw this question, and it makes me pessimistic, but here I don't need a regex, and I need to somehow figure out which hunks are added versus rejected.

Add patch in git, all hunks matching regex in file

v2v1
  • 640
  • 8
  • 18

1 Answers1

0

There is nothing built in. However, git add -p is a Perl program; if you are fluent in Perl it will be easy to hack it into the code. Just take each diff hunk and apply a test subroutine to it, and add it if it passes the test rather than if an interactive query to the user says "yes".

torek
  • 448,244
  • 59
  • 642
  • 775