Git alias returns an error when using pipe command

為{幸葍}努か 提交于 2019-12-02 10:26:54

The first thing to note is that git aliases only work with shell commands when prefixed with a bang (exclamation mark). I'm not using git-ftp so I can't test your precise command, but I used git remote show origin instead because it's very verbose on one of my repos. I found the following git alias worked fine: sh = "!git remote show origin | awk 'NR<7'" I therefore expect this git alias to be a solution for you:

sh = "!git ftp show | awk 'NR<7'"

Realise that some bang/pipe/quote combinations work as git aliases, while others will fail, possibly with "fatal bad config line". Most often the real problem is how quotes are used. The trick can be to just change your particular git alias shell command line to eliminate or change quote usage. For instance one requirement for a git alias that I had, I worked around the quote problem by changing a sed command to tr. I then had to double escape a backslash using: ...| tr \\\\n.

For this particular question, although I don't think git-alias has a problem with the quotes, a more quote-safe solution would be:

sh = ! git ftp show | head -6

While most readers may already know about the requirement to shell out with a bang, they may not realise that quoting is a more difficult issue. Although not entirely correct, I found this article was useful for ideas: https://www.atlassian.com/blog/git/advanced-git-aliases

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!