【问题标题】:how to alias git flow hotfix finish [current_hotfix_branch]如何为 git flow hotfix 完成别名 [current_hotfix_branch]
【发布时间】:2016-02-03 00:17:51
【问题描述】:

git flow 任何时候只允许一个 hotfix 分支。所以不要输入:

git flow hotfix finish hotfix_branch

我想创建一个使用唯一现有修补程序分支名称的别名。类似于以下伪代码:

[alias]
  fix-done = flow hotfix finish `git_fetch_branch_beginning_with_hotfix`

有人可以帮忙吗?谢谢。

更新:我正在使用 zsh。

【问题讨论】:

    标签: git alias git-flow


    【解决方案1】:

    这个函数或多或少是从git-flow的源代码中提取出来的:

    finish_current_hotfix_branch ()
    {
      local hotfix_prefix=$(git config --get gitflow.prefix.hotfix)
      local hotfix_branches=$(echo "$(git branch --no-color | sed 's/^[* ] //')" | grep "^$hotfix_prefix")
      local first_branch=$(echo ${hotfix_branches} | head -n1)
      first_branch=${first_branch#$hotfix_prefix}
      git flow hotfix finish "$first_branch"
    }
    

    更新

    看来您必须将整个函数放在别名中。不好,但可以:

    [alias]
      fix-done ="!_() { p=$(git config --get gitflow.prefix.hotfix); b=$(echo \"$(git branch --no-color | sed 's/^[* ] //')\" | grep \"^$p\"); f=$(echo ${b} | head -n1); f=${f#$p}; git flow hotfix finish \"$f\"; }; _"
    

    【讨论】:

    • 谢谢,current_hotfix_branch 对我有用,但在 git 别名中使用时不起作用。作为更新,我使用的是 zsh,所以我将该方法隐藏在 .zshrc 中。与 git 别名一样,对此有何想法?谢谢
    • @ZacZheng 你说得对,这样不行。我已经更新了我的答案。
    • 谢谢@Stefan。我已经接受了,因为它完成了这项工作。不过,仍然愿意接受一个不那么突兀的解决方案!
    【解决方案2】:

    这里是另一种方式来做 git flow hotfix finish alias:

    hf = "!_() { b=$(git rev-parse --abbrev-ref HEAD) && git co master && git pl && git co develop && git pl && git co $b && git rebase master && h=$(echo $b | sed 's/hotfix\\///g') && git flow hotfix finish -m 'new_tag' $h && git co master && git ps && git co develop && git ps && git ps --tags && git poo $b && git br -D $b;  }; _"
    

    【讨论】:

      【解决方案3】:

      如果你运行 git flow AVH 版,你可以这样做

      $ git flow finish
      

      当你在你想要完成的分支上时。这适用于修补程序、发布、功能和错误修复。

      检查你是否运行 git flow AVH 版

      $ git flow version
      x.xx.x (AVH Edition)
      

      【讨论】:

        猜你喜欢
        • 2012-11-07
        • 1970-01-01
        • 1970-01-01
        • 2012-06-08
        • 2012-04-09
        • 2011-09-01
        • 2015-04-28
        • 2015-07-09
        • 1970-01-01
        相关资源
        最近更新 更多