功能分支的好git过程

时间:2013-08-27 12:36:38

标签: git github git-rebase

我们一直在我们的团队中来回讨论个别开发人员使用功能分支,变基等的最佳流程。以下是我们提出的(来自某些邮件列表的输入)但它似乎有点复杂&有很多步骤。还有其他SO问题,其中一些答案示例似乎相似且更简单。

这是一个很好的工作流程吗?怎么可以简化(如果有的话)或改变?

git checkout develop # all developer work is off of this branch
git pull --rebase # make sure local develop is up-to-date
git checkout -b my-nifty-feature-559876 # create your feature branch; I like to put Pivotal story ID in it for convenience; not required

# do your work, make sure all tests still pass, etc. COMMIT FREQUENTLY
git commit -m "First part of my nifty feature working; now on to the back-end."

# fetch latest remote develop and rebase your local feature branch on this.
git fetch
git rebase origin/develop
# Local feature branch now has latest origin/develop code as base

# repeat above 3 frequently as you're working

# when you're done, pull and rebase one last time, make sure tests pass, then final commit with Pivotal comment
git commit -m "It works! [Fixes #559876]" # commit when done. Include comment like that for Pivotal integration
git fetch
git rebase origin/develop

# Local feature branch now has latest origin/develop code as base

git checkout develop # switch back to develop
git pull
git merge my-nifty-feature-559876 # This should be a simple FF merge
git push origin develop # send to github
git branch -d my-nifty-feature-559876 # you can get rid of your feature branch

1 个答案:

答案 0 :(得分:-1)

这几乎是 git工作流程。几乎所有其他VCS也是如此。

git rebase origin/developgit merge origin/develop相比是一个品味问题,但两者在最终结果中基本相同。 Rebase提供了更清晰的历史记录,但合并意味着您可以随时回滚到昨天的位置。

同样,有时我更喜欢与--squash进行最后一次合并,以保持主分支历史更清晰。

我认为不可选的一个小提示:在rebase之前备份。如果你使用rebase来重写历史记录,你就有可能毁掉一切然后无法回滚。

git branch my-nifty-feature-559876-BACKUP
git rebase origin/develop

# verify everything rebased ok
git branch -D my-nifty-feature-559876-BACKUP

创建新分支意味着您在rebase之前拥有功能分支的副本。如果rebase出现严重错误,您可以使用reset回滚。