Can I modify git-add's **default** hunk size?

心不动则不痛 提交于 2019-12-18 16:47:14

问题


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).


回答1:


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.

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 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.



来源:https://stackoverflow.com/questions/33891010/can-i-modify-git-adds-default-hunk-size

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!