2017-08-18 111 views
1

我想创建一个Git别名,这样我就可以一次运行多个命令。无法创建git别名?

我键入以下到终端:

混帐配置alias.cleanpull “混帐的复位 - 硬头; git的清洁-f; Git的 拉!”

我认为是正确的语法,但我立即得到下面的输出输入命令后(自定义命令即不实际运行它):

git config alias.cleanpull "git config cleanpull.q "git push --all origin reset --hard HEAD; git clean -f; git pull" reset --hard HEAD; git clean -f; git pull" 
usage: git config [<options>] 

Config file location 
    --global    use global config file 
    --system    use system config file 
    --local    use repository config file 
    -f, --file <file>  use given config file 
    --blob <blob-id>  read config from given blob object 

Action 
    --get     get value: name [value-regex] 
    --get-all    get all values: key [value-regex] 
    --get-regexp   get values for regexp: name-regex [value-regex] 
    --get-urlmatch  get value specific for the URL: section[.var] URL 
    --replace-all   replace all matching variables: name value [value_regex] 
    --add     add a new variable: name value 
    --unset    remove a variable: name [value-regex] 
    --unset-all   remove all matches: name [value-regex] 
    --rename-section  rename section: old-name new-name 
    --remove-section  remove a section: name 
    -l, --list   list all 
    -e, --edit   open an editor 
    --get-color   find the color configured: slot [default] 
    --get-colorbool  find the color setting: slot [stdout-is-tty] 

Type 
    --bool    value is "true" or "false" 
    --int     value is decimal number 
    --bool-or-int   value is --bool or --int 
    --path    value is a path (file or directory name) 

Other 
    -z, --null   terminate values with NUL byte 
    --name-only   show variable names only 
    --includes   respect include directives on lookup 

git: 'pull reset --hard HEAD; git clean -f; git pull' is not a git command. See 'git --help'. 
+1

!必须以\!的形式逃脱。它对bash有特殊的意义。 –

+0

@AlexeyTen您有没有作为回答发布的原因? –

+0

从手机难以打字。随意添加 –

回答

1

shell中的问题(我猜你有bash,这是最常见的,但它可能是csh或其他),而不是git。 Bash威胁!特别作为命令历史的参考符号。为了使用它字面上,你必须要么反斜杠(\!)逃避它

git config alias.cleanpull "\!git reset --hard HEAD; git clean -f; git pull" 

,或者使用单引号

git config alias.cleanpull '!git reset --hard HEAD; git clean -f; git pull' 

欲了解更多信息请参见历史扩展bash manual

+0

如果我没有记错,'bash'从'sh'继承了这个行为,它是复制和扩展的原始Bourne shell。当使用其他从'sh'行为中获得启发的shell时,也可能发生这种情况。 – axiac

+0

@axiac提及其他炮弹。 'sh'(在我的系统中是'dash')和'ksh'不这样做。由'csh'做。我懒得测试其他shell。 –

+0

这只是一个侧面的评论,没什么好担心的。问题的标签是[tag:bash],你的回答清楚地解释了如何解决Bash的问题。和文档的链接绝对是一个很好的答案。 – axiac