gpt4 book ai didi

git - 在 gitconfig 中设置多个替代案例的脚本

转载 作者:行者123 更新时间:2023-12-03 08:02:04 26 4
gpt4 key购买 nike

我需要一个脚本来确保 .gitconfig 文件中包含以下内容:

[url "git@<IP addr>:"]
insteadOf = https://<IP addr>/
insteadOf = https://<domain name>/
insteadOf = git@<domain name>:

这是为了确保用户始终使用 SSH 进行克隆,并使用 IP 地址而不是 HTTP 地址(以 IP 或域形式),并且使用域名而不是 ssh。

但是,使用以下代码:

git config --global url.git@<IP addr>:.insteadOf https://<IP addr>/ --replace-all
git config --global url.git@<IP addr>:.insteadOf https://<domain name>/ --add
git config --global url.git@<IP addr>:.insteadOf git@<domain name>: --add

这工作正常,但是一旦脚本再次运行,它会重新打印 .gitconfig 文件中的行,随着时间的推移,这将使文件太大并且 git 速度太慢。我已经尝试了标志 --replace-all --add 等的所有组合。他们要么堆积文件,要么发出警告,由于项目要求,我也无法容忍。

Is there any syntax to add the three lines at once and do nothing if they're already there?

最佳答案

在我看来,这就像混合选项和参数样式的选项解析中的错误,

git config --global --replace-all url.git@<IP addr>:.insteadOf https://<IP addr>/
git config --global --add url.git@<IP addr>:.insteadOf https://<domain name>/
git config --global --add url.git@<IP addr>:.insteadOf git@<domain name>:

有效。

关于git - 在 gitconfig 中设置多个替代案例的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73840583/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com