0
我试图做一些疯狂的git-fu带有别名。具体来说,我希望一个git别名根据它们是否为空来读取传入的参数,以不同的方式处理命令;有点像重载一个函数。我已经为从this one等其他问题创建函数获得了一些很好的想法,但以智能方式处理参数仍然无法解决。在git别名函数中使用和检查可选参数
我最终做的是创建3个函数,用于不同级别的特异性,并使用默认值在链中调用它们。这是我在我的git配置中的一部分。
# get the current local branch
current = symbolic-ref -q --short HEAD
# Calls sync-branch-with-origin-master using the current branch for the first property and origin as the remote name.
# ex. `git sync master` will checkout master from origin, pull the latest, checkout your current branch and rebase it with master.
sync = "!f() { currentBranch=$(git current); git sync-branch-with-master $currentBranch $1; }; f"
# get latest version of branch 2 from origin and rebase branch 1 onto it.
sync-branch-with-master = "!f() { git sync-branch-with-origin-master $1 origin $2; }; f"
# get latest version of branch $3 from origin $2 and rebase branch $1 onto it.
sync-branch-with-origin-master = "!f() { git checkout $3; git pull $2 $3; git checkout $1; git rebase $3; }; f"
这很好用!但我真正喜欢的是检查是否存在3美元或2美元,并以不同方式处理这些情况。
顺便说一下,我在Mac上使用bash。