简体   繁体   English

如何在.gitconfig别名上使用bash命令

[英]How to use bash commands on .gitconfig aliases

I use the command git ls-tree -r $(git branch | awk '{ print $2 }') --name-only to show the files on my branch, but i tried to put this command on my .gitconfig file as an alias and i got this error: 我使用命令git ls-tree -r $(git branch | awk '{ print $2 }') --name-only来显示我的分支上的文件,但我试图将此命令放在我的.gitconfig文件上别名,我收到此错误:

$ git list
fatal: Not a valid object name $(git

My .gitconfig file: 我的.gitconfig文件:

[alias]
list = ls-tree -r $(git branch | awk '{ print $2 }') --name-only

Thanks PD Sorry for my english 谢谢PD抱歉,我的英文

As already pointed out in comments, you need to prefix your alias with an exclamation ( ! ) mark. 正如评论中已经指出的那样,您需要在别名前加上感叹号( ! )标记。

The following entry works for me 以下条目适合我

[alias]
    list = !git ls-tree -r $(git branch | awk '{ print $2 }') --name-only

EDIT 编辑

Alternatively, taking help from this answer , you can create a file git-list in any place in your PATH , like below: 或者,从这个答案中获得帮助,您可以在PATH任何位置创建一个文件git-list ,如下所示:

git-list 混帐列表

git ls-tree -r $(git branch | awk '{ print $2 }') --name-only

then change its permission to executable using chmod +x git-list and you can have your git list command working in any directory. 然后使用chmod +x git-list将其权限更改为可执行文件,您可以在任何目录中使用git list命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM