简体   繁体   English

在 Git 别名中使用条件?

[英]Using conditionals in a Git alias?

I want to add a confirmation before my Git aliases, eg:我想在我的 Git 别名之前添加一个确认,例如:

amend = !echo -n 'Confirm: ' && read 'x' && [ $x == 'y' ] && git add -A && git commit -a --amend

This works directly in the terminal, but when I run it as a Git alias, I get:这直接在终端中工作,但是当我将它作为 Git 别名运行时,我得到:

echo -n 'Confirm: ' && read 'x' && [ $x == 'y' ] && git add -A && git commit -a --amend: 1: [: y: unexpected operator

How can I make this work?我怎样才能使这项工作?

I am suspecting that git aliases use sh by default.我怀疑 git 别名默认使用sh Try replacing the == in your test command by = :尝试将测试命令中的==替换为=

amend = !echo -n 'Confirm: ' && read 'x' && [ $x = 'y' ] && git add -A && git commit -a --amend

The == is defined by bash , but not by POSIX. ==bash定义,但不是由 POSIX 定义。 http://www.gnu.org/software/bash/manual/html_node/Bash-Conditional-Expressions.html http://www.gnu.org/software/bash/manual/html_node/Bash-Conditional-Expressions.html

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

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