Git别名和位置参数 [英] Git alias with positional parameters

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

问题描述

基本上我想尝试别名:

  git文件9fa3 
/ pre>

...执行命令:

  diff --name-status 9fa3 ^ 9fa3 

但是git似乎不能将位置参数传递给alias命令。我试过:

  [别名] 
files =!git diff --name-status $ 1 ^ $ 1
files =!git diff --name-status {1} ^ {1}



<



退化的情况是:

  $ git echo_reverse_these_params abcde 
edcba

解决方案

最明显的方法是使用shell函数:

  [别名] 
files =!f(){git diff --name-status$ 1 ^$ 1;} f

不处理的别名作为Git命令;例如 commit-all = commit -a



使用,它在shell中以自己的命令运行,让你使用更强的魔法。


Basically I'm trying to alias:

git files 9fa3

...to execute the command:

git diff --name-status 9fa3^ 9fa3

but git doesn't appear to pass positional parameters to the alias command. I have tried:

[alias]
    files = "!git diff --name-status $1^ $1"
    files = "!git diff --name-status {1}^ {1}"

...and a few others but those didn't work.

The degenerate case would be:

$ git echo_reverse_these_params a b c d e
e d c b a

...how can I make this work?

解决方案

The most obvious way is to use a shell function:

[alias]
    files = "!f() { git diff --name-status "$1^" "$1"; }; f"

An alias without ! is treated as a Git command; e.g. commit-all = commit -a.

With the !, it's run as its own command in the shell, letting you use stronger magic like this.

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

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