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:
export GIT_DIFF_OPTS=-u0
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.
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 the diff.context
setting:
git config --global diff.context 0
Interestingly, you can also configure the number of lines to include between hunks with the diff.interHunkContext
setting:
git config --global diff.interHunkContext 0
Setting it to 0
will effectively concatenate the hunks one after the other.