如果不使用 shell,我可以在 git 别名上使用参数吗?
例如,我的主要远程分支始终称为“上游”,有时 git 会丢失本地分支的引用并说:
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=<remote>/<branch> master
我想要一个别名,例如
[alias]
reup = branch --set-upstream-to=upstream/$1 $1
这样我就可以输入git reup master
(或者更好的是,将 git 配置为始终假定远程为“上游”?)
最佳答案
不使用外壳?不。但是对于 shell,当然可以:
[alias]
brup = "!f() { git branch --set-upstream-to=${2:-origin}/$1 $1; }; f"
现在,您可以运行 git brup dev
将上游设置为 origin/dev
或 git brup devupstream
将上游设置为 上游/dev
。
关于git - 如果我必须在两个地方重复相同的文本,git 别名可以使用参数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50297197/