以root身份提交时如何使用我的个人git配置?

问题描述 投票:2回答:1

我使用etckeeper来修改我的/etc目录。

由于/etc下文件的所有权,我需要以root身份运行git

我怎么能这样做,仍然可以轻松访问我所有我心爱的git别名和其他配置?

git sudo git-config
1个回答
2
投票

git -c include.path=<file>将在<file>中包含配置。

要自动提取我的非root用户的配置文件,我使用bash别名:

alias gsudo='sudo git -c "include.path='"${XDG_CONFIG_DIR:-$HOME/.config}/git/config\" -c \"include.path=$HOME/.gitconfig\""

然后我使用gsudo而不是git

  • 以root身份运行
  • 可以访问所有非root用户git配置

检查配置是否确实正在导入:

gsudo config --list --show-origin --includes | less

当然,如果你有任何root-unsafe配置,你应该小心。

或许同时拥有“安全”和“潜在危险”的配置文件是可行的方法。用户的~/.config/git/config可能是“潜在的危险”,[include]s是“安全”的root-only配置文件(这是gsudo别名中唯一使用的配置文件)。

© www.soinside.com 2019 - 2024. All rights reserved.