代码之家  ›  专栏  ›  技术社区  ›  Jacob Rask

切换分支时调用外部命令

  •  3
  • Jacob Rask  · 技术社区  · 16 年前

    我想在切换分支后重新启动我的虚拟服务器,并尝试在我的 .gitconfig

    co = checkout | !rap
    

    只运行rap,重启脚本。

    co = checkout && !rap
    

    checkout $1 )给出了我的“git用法:bla-bla”。

    2 回复  |  直到 14 年前
        1
  •  3
  •   Michael Krelin - hacker    16 年前

    备注 正确的解决方案 问题 post-checkout hook ,如所写 hacker's answer .

    下面是您的可能解决方案 .


    您可以在别名中使用单个git命令,例如。

    [alias]
        alias = config --get-regexp ^alias\\.
    

    或者使用任何带有“!”的命令!'前缀,可能使用“ sh -c

    [alias]
        sed = !git ls-files --stage | grep ^100 | awk '{print $4}' | xargs sed
        who = "!sh -c 'git log -1 --pretty=\"format:%an <%ae>\" --author=\"$1\"' -"
    

    alias.sed


    git br <somebranch> git checkout <somebranch> “那么” rap

    [alias]
        br = !sh -c 'git checkout "$0" && rap'
    

    这里 && ; 而是运行命令,而不管早期命令的状态如何

    分支使用” git checkout <branch> git branch <branchname> " 分支,没有检查出来。

        2
  •  6
  •   Community Mohan Dere    9 年前

    post-checkout .git/hooks/ 目录和 githooks manpage ).