【问题标题】:How to set tab size for hunks in "git add -p"?如何在“git add -p”中设置大块的标签大小?
【发布时间】:2013-08-04 18:54:50
【问题描述】:
我使用解决方案here 更改git diff 输出中的标签大小。这适用于git diff。
我的 .gitconfig 中有这些设置:
[core]
whitespace = tabsize=4,indent-with-non-tab
pager = less -FSRX -x4
但这些设置似乎不会影响git add -p。
如何在git add -p 命令中设置大块的标签大小?
【问题讨论】:
标签:
git
version-control
tabs
git-add
tab-size
【解决方案1】:
core.pager 设置不会影响git add -p 命令,因为git add -p 不会通过less/pager。要更改 hunks 选项卡大小,您需要更改终端的选项卡大小。找到解决方案here。刚刚在.bashrc中添加:
env TERM=linux setterm -regtabs 4
该设置在 xterm 终端中运行良好。对于其他终端类型,请查看手册以获得正确的解决方案。
【解决方案2】:
您可以使用 setterm --tabs 可视化当前的制表位。
对于“git add -p”,您可能希望制表位看起来像这样:
10 20 30 40 50
12345678901234567890123456789012345678901234567890123456789
T T T T T T T T T T T T T T
不是这个:
10 20 30 40 50
12345678901234567890123456789012345678901234567890123456789
T T T T T T T T T T T T T T
要获得第一个,您可以使用tabs -c3 (read here)。
要获得第二个,您可以使用tabs -4。
但是,如果您使用 tabs -c3(cat 需要 tabs -4),则会破坏您的 cat 输出。
所以只有在运行git add -p时才需要tabs -c3。
这是我的做法:
git() {
if [[ "$1" == "add" ]] &&
[[ "$2" == "-p" ]] || [[ "$2" == "--patch" ]]
then
tabs -c3
if [[ "$#" -eq 2 ]]
then
command git add -p
else
command git add -p "$3"
fi
tabs -4
else
command git "$@"
fi
}
把它放在你的 .bashrc 和/或 .zshrc