Using git add -p
, one can select changes to a file for staging.
One can manually change the hunk size (Can I modify git-add's hunk size?), but I would like to know how to change the default hunk size (for example to a single line).
Using git add -p
, one can select changes to a file for staging.
One can manually change the hunk size (Can I modify git-add's hunk size?), but I would like to know how to change the default hunk size (for example to a single line).
You can use the
GIT_DIFF_OPTS
environment variable to tell Git how many lines of context it should include in a hunk every time it has to generate a patch.In your case, you would say:
where the
-u0
option (the short version of--unified
) puts 0 lines of context in each hunk, which effectively reduces it to only contain the lines that have changed.Update (2018-11-01)
If you're just interested in changing the default hunk size in the output of
git diff
, you can set it in your.gitconfig
file by using thediff.context
setting:Interestingly, you can also configure the number of lines to include between hunks with the
diff.interHunkContext
setting:Setting it to
0
will effectively concatenate the hunks one after the other.