Git:可以在 .gitconfig 中引用 .gitconfig 中的变量吗?
Git: Referencing of variables from .gitconfig in .gitconfig possible?
是否可以在 .gitconfig 的另一个定义中使用 .gitconfig 中的变量?
在bash我能做到:
delimiter="^"
log_res="log --graph --pretty=format:'$delimiter%cr$delimiter%cs$delimiter%h'"
结果是
log --graph --pretty=format:'^%cr^%cs^%h'
是否可以在 .gitconfig 中实现 result 别名???
[alias]
result = log --graph --pretty=format:'^%cr^%cs^%h'
delimiter = "^"
log-res = ??? log --graph --pretty=format:'DELIMITER%crDELIMITER%csDELIMITER%h' ???
我如何写 'log-res' 分隔符的更改被接管?这个能不能做好?
我知道我可以做这样的事情,如果你定义了很多日志命令,那就太丑了:
[alias]
result = log --graph --pretty=format:'^%cr^%cs^%h'
delimiter = "^"
log-res = !bash -c '"git $(echo \"log --decorate=short --graph --pretty=format:'$(git config alias.delimiter)%cr$(git config alias.delimiter)%cs$(git config alias.delimiter)%h'\")"'
其中 git result
与 git log-res
相同,但这读起来很糟糕,不是吗?
不,无法在 .gitconfig
中引用其他设置。一般来说,这会很棘手,因为继承规则:如果 repo 本地配置中的值发生变化,全局配置中的别名会使用全局配置或 repo 本地配置中的版本吗?
如您所见,您确实可以使用 sh
来执行此操作,但它可以更简单一些:
log-res = "!f() { d=\"$(git config alias.delimiter)\"; git log --graph --pretty=\"format:$d%cr$d%cs$d%h\" \"$@\"; };f"
您可能希望将值存储在 alias
部分以外的其他位置,这样您的 shell 完成就不会尝试完成 git delimiter
,这是行不通的.
是否可以在 .gitconfig 的另一个定义中使用 .gitconfig 中的变量?
在bash我能做到:
delimiter="^"
log_res="log --graph --pretty=format:'$delimiter%cr$delimiter%cs$delimiter%h'"
结果是
log --graph --pretty=format:'^%cr^%cs^%h'
是否可以在 .gitconfig 中实现 result 别名???
[alias]
result = log --graph --pretty=format:'^%cr^%cs^%h'
delimiter = "^"
log-res = ??? log --graph --pretty=format:'DELIMITER%crDELIMITER%csDELIMITER%h' ???
我如何写 'log-res' 分隔符的更改被接管?这个能不能做好?
我知道我可以做这样的事情,如果你定义了很多日志命令,那就太丑了:
[alias]
result = log --graph --pretty=format:'^%cr^%cs^%h'
delimiter = "^"
log-res = !bash -c '"git $(echo \"log --decorate=short --graph --pretty=format:'$(git config alias.delimiter)%cr$(git config alias.delimiter)%cs$(git config alias.delimiter)%h'\")"'
其中 git result
与 git log-res
相同,但这读起来很糟糕,不是吗?
不,无法在 .gitconfig
中引用其他设置。一般来说,这会很棘手,因为继承规则:如果 repo 本地配置中的值发生变化,全局配置中的别名会使用全局配置或 repo 本地配置中的版本吗?
如您所见,您确实可以使用 sh
来执行此操作,但它可以更简单一些:
log-res = "!f() { d=\"$(git config alias.delimiter)\"; git log --graph --pretty=\"format:$d%cr$d%cs$d%h\" \"$@\"; };f"
您可能希望将值存储在 alias
部分以外的其他位置,这样您的 shell 完成就不会尝试完成 git delimiter
,这是行不通的.