Windows 版 Git 有 a problem写入位于网络上的配置文件。
以下可以用作该错误的解决方法:
mv "//hyprostr/dfs/groups/developers/settings/gitconfig.txt" "./gitconfig.txt"
git config -f "./gitconfig.txt" http.proxy http://@proxy2:8080
mv "./gitconfig.txt" "//hyprostr/dfs/groups/developers/settings/gitconfig.txt"
这不是一个很好的解决方案,但它对我有用。
但我想通过 Git 别名调用这组命令...注意 - 第一个和最后一个命令是外部命令,而第二个命令是内部命令。
我阅读了关于 alias.*
的 git help config
部分。读完后我认为不可能通过别名来编写这三个命令。我对吗?我希望我是错的,但这是可能的。如果我错了,那我该怎么办?
UPD(决定)
感谢@VonC的回答。我写了这样的脚本:
# edit_config.sh
# © Andrey Bushman, 2015
# This is a workaround of the problem described here:
# https://github.com/git-for-windows/git/issues/241
# Arguments:
# $1 - target config file
# $2 - parameter full name
# $3 - parameter value
random_file_name=$RANDOM
mv $1 $random_file_name
git config -f $random_file_name $2 $3
mv $random_file_name $1
我也在网络中找到了脚本文件。现在可以直接通过 Git Bash 启动它:
sh "//hyprostr/dfs/groups/developers/settings/edit_config.sh" "//hyprostr/dfs/groups/developers/settings/gitconfig.txt" "http.proxy" "http://@proxy2:8080"
或通过别名
git config --global alias.editconfig '!sh "//hyprostr/dfs/groups/developers/settings/edit_config.sh"'
我可以启动这个:
git editconfig "//hyprostr/dfs/groups/developers/settings/gitconfig.txt" "http.proxy" "http://@proxy2:8080"
对我来说效果很好。
最佳答案
如果无法直接实现,您仍然可以:
- 编写一个执行这些命令的 shell 脚本(sh:甚至在 Windows 上)
- 将该脚本添加为 git 别名。
参见“How to embed bash script directly inside a git alias”
git config --global alias.diffall '!sh myscript.sh'
实际上,如果您的脚本名为 git-xxx
,您甚至不需要别名:git xxx
就可以工作(并调用 git- xxx
脚本文件)。
关于git - 我可以对 Git 别名使用一组命令(外部和内部)吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31447193/