具有多个命令的Git别名的语法 [英] Syntax for Git aliases with multiple commands

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

问题描述


  1. 什么是Git别名?具有多个命令的Git别名的语法?
  2. 配置'


     别名。* 
    code>

    git(1)命令包装的命令别名 - 例如在定义alias.last = cat-file commit HEAD之后,调用git
    last等价于git cat-file commit HEAD。为了避免混淆

    脚本使用的麻烦,隐藏现有Git命令的别名将被忽略。参数由空格分开,支持通常的shell
    引用和转义。引用对和反斜线可以是

    引用它们。



    如果别名扩展以感叹号为前缀,则会对其进行处理作为shell命令。例如,定义
    alias.new =!gitk --all --not ORIG_HEAD,调用git new为
    等价于运行shell命令gitk --all - not ORIG_HEAD 。请注意,shell命令将从存储库的
    顶级目录中执行,该目录可能不一定是
    当前
    目录。 GIT_PREFIX被设置为通过从原始当前目录运行git rev-parse --show-prefix返回。请参阅
    git-rev-parse(1)。


    解决方案

    $ git config alias.q'!echo a; echo b'

    $ git q

    输出:

      a 
    b

    我认为这是(基本)记录在 man git-config 下的别名。*



    请注意,与正常的别名不同,git命令应该包含git。它是由事实引起的,它被视为shell命令,而不是git命令(请参阅问题中引用的manpage)。例如,链

      git init 


    $ b

      git commit --allow-empty -m空初始提交

    有必要创建

     !git init; git commit --allow-empty -m \empty initial commit\

    别名。


    I want to create a Git alias to perform multiple commands, but I cant find documentation on how this is done.

    1. What is the syntax for Git aliases with multiple commands?
    2. Where is this documented?

    From 'man git-config'

       alias.*
    

    Command aliases for the git(1) command wrapper - e.g. after defining "alias.last = cat-file commit HEAD", the invocation "git last" is equivalent to "git cat-file commit HEAD". To avoid confusion and troubles with script usage, aliases that hide existing Git commands are ignored. Arguments are split by spaces, the usual shell quoting and escaping is supported. quote pair and a backslash can be used to quote them.

    If the alias expansion is prefixed with an exclamation point, it will be treated as a shell command. For example, defining "alias.new = !gitk --all --not ORIG_HEAD", the invocation "git new" is equivalent to running the shell command "gitk --all --not ORIG_HEAD". Note that shell commands will be executed from the top-level directory of a repository, which may not necessarily be the current directory. GIT_PREFIX is set as returned by running git rev-parse --show-prefix from the original current directory. See git-rev-parse(1).

    解决方案

    $ git config alias.q '!echo a; echo b'
    
    $ git q
    

    Output:

    a
    b
    

    I think this is (rudimentarily) documented in man git-config under alias.*

    Note that git commands should include git, unlike in normal aliases. It is caused by fact that it is treated as a shell command, not as a git command (see manpage quoted in the question). For example to chain

    git init
    

    and

    git commit --allow-empty -m "empty initial commit"
    

    it is necessary to create

    "!git init; git commit --allow-empty -m \"empty initial commit\""
    

    alias.

    这篇关于具有多个命令的Git别名的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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