Multiple Commands and Parameters

I am trying to create an alias that uses both multiple Git commands and positional parameters. There are Stackoverflow pages for each, and it would appear painfully obvious to do both, but I am having trouble.

As an example, I want to switch to branch foo and perform a status. So in my .gitconfig , I have:

  [alias] 
     chs = !sh -c 'git checkout $0 && git status'

which doesn't work. Whereas something like this will work.

chs = !sh -c 'git checkout $0'

echoes = !sh -c 'echo hi && echo bye'

Any insight would be appreciated.


这将工作(用zsh和bash测试):

[alias] chs = !git checkout $1 && git status

你可以定义一个shell函数。

[alias] chs = "!f(){ git checkout "$1" && git status; };f"

This targets Windows batch / msysgit bash; might not work on other environments.

As Olivier Verdier and Kevin Ballard have said

[alias] chs = !git checkout $1 && git status

almost works, but gives a spurious extra insertion of the argument ...

git chs demo -> git checkout demo && git status demo

But if you add && : to the end of your alias, then the spurious argument is consumed into a location tag.

So

[alias] chs = !git checkout $1 && git status && :

gives the correct output ... git chs demo -> git checkout demo && git status

链接地址: http://www.djcxy.com/p/49762.html

上一篇: 具有多个命令的Git别名的语法

下一篇: 多个命令和参数