如何直接在 git 别名中嵌入 bash 脚本 [英] How to embed bash script directly inside a git alias
问题描述
我可以嵌入以下 bash shell 代码吗:
Can I embed the following bash shell code:
for name in $(git diff --name-only $1); do git difftool $1 $name & done
直接进入创建git别名:
directly into the creation of a git alias:
git config --global alias.diffall ***my-bash-code-here***
这源于我的上一个关于 SO 的问题/答案,我将代码放入 .sh 文件中,然后为该文件设置别名:
This leads on from my previous question/answer on SO, where I put the code into a .sh file and then aliased to the file:
git config --global alias.diffall '!sh diffall.sh'
但是在对简单性的永无止境的追求中,必须有一种方法可以跳过文件并将代码直接插入别名中吗?我无法弄清楚格式...
But in the never-ending quest for simplicity, there's gotta be a way to skip the file and insert code directly into the alias? I can't figure out the format...
推荐答案
git config --global alias.diffall '!sh diffall.sh'
这在一方面是多余的.如果您无论如何都要将diffall.sh"添加到您的 $PATH 中,为什么不将其另存为git-diffall",并避免声明别名.是的,git diffall"会运行它.
This is redundant in one way. If you are going to add 'diffall.sh' into your $PATH anyway, why not save it as 'git-diffall', and save yourself from declaring an alias. Yes, "git diffall" will run it.
这篇关于如何直接在 git 别名中嵌入 bash 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!