Git别名 - 多个命令和参数 [英] Git Alias - Multiple Commands and Parameters

查看:158
本文介绍了Git别名 - 多个命令和参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试创建一个同时使用多个Git命令和位置参数的别名。每个都有一个Stackoverflow页面,这两个页面都显得很痛苦,但我遇到了麻烦。



作为一个例子,我想切换到分支foo和执行状态。所以在我的 .gitconfig 中,我有:

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

不起作用。然而,类似这样的东西是可行的。

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

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

任何见解都会被赞赏。
$ b

  [别名] 

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


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.

解决方案

This will work (tested with zsh and bash):

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

这篇关于Git别名 - 多个命令和参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆