使用Gitflow与拉取请求的正确方式

52

我想在我的团队中采用git-flow工具。

问题是,“git flow feature finish”会在本地合并分支。 而我想创建一个pull request代替。这样,合并将在远程仓库中进行。

那么,在与使用pull request的团队中使用git-flow工具的正确方法是什么?

尝试了谷歌搜索,但没有找到有意义的东西。


1
Git flow并不是一个工具,它是一种策略,有一些扩展可以帮助实现这个策略。 - evolutionxbox
3个回答

54
您可以使用git flow feature publish 命令将您的功能分支发布到源头(例如Bitbucket)。然后,在那里创建拉取请求并将其合并到develop分支中。完成后,需要手动删除本地功能分支。
唯一不能使用的命令是git flow feature finish 。这种方法效果不错,您仍然可以使用大多数git flow助手。
对于发行版也是如此。我发现这篇文章很有帮助:https://blog.axosoft.com/pull-requests-gitflow/ 以及https://community.atlassian.com/t5/Bitbucket-questions/git-flow-feature-finish-and-pull-request/qaq-p/347877 希望这能稍微有所帮助。没有一个完美的解决方案。

4

这个问题有一个很好的解决方案,但需要使用自定义脚本,因为PR API对每个平台都是独特的。

git-flow的AVH版本具有一些额外的功能: https://github.com/petervanderdoes/gitflow-avh

它支持挂钩(自定义脚本): https://github.com/petervanderdoes/gitflow-avh/wiki/Reference:-Hooks-and-Filters#hooks

您可以在Mac上切换到AVH版本:

brew uninstall git-flow
brew install git-flow-avh

为了支持 git flow 中的 pull request,您可以添加一个脚本:
.git/hooks/post-flow-feature-publish.sh

这是一个示例脚本post-flow-feature-publish.sh,用于输出一个URL:

#!/bin/sh

branch=$(git rev-parse --abbrev-ref HEAD)
userRepo=$(git remote -v | grep fetch | awk '{print $2}' | grep "github.com" | cut -d':' -f2 | rev | cut -c5- | rev)

if [ -n "$userRepo" ]
then
    echo ""
    echo "Create PR at: https://github.com/$userRepo/compare/$branch?expand=1"
    echo ""
fi

如果您使用GitHub CLI,则可以调用:gh pr createhttps://cli.github.com/manual/gh_pr_create

现在运行命令时:

git flow feature my-feature publish

Git flow会将代码推送到功能分支,并调用挂钩脚本来创建PR。


5
你在哪里可以找到 post-flow-feature-publish.sh 脚本?并不是大多数人都熟悉 Github REST API。 - oligofren
1
您需要创建.git/hooks/post-flow-feature-publish.sh文件,并添加命令以创建GitHub PR。如果使用GitHub CLI,您应该能够调用:gh pr create https://cli.github.com/manual/gh_pr_create - Kim T

1
  1. 开始你的功能分支:git flow feature start my-feature
  2. 开发功能并提交相关更改。
  3. 发布功能:git flow feature publish my-feature
  4. 前往例如Gitlab创建合并请求,进行审查并合并(不要删除源/功能分支)。
  5. 切换到'develop'并从远程仓库拉取所有更改:git checkout develop && git pull
  6. 最后一步,完成功能:git flow feature finish my-feature。它将从本地和远程仓库中删除'my-feature'分支。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接