2013-08-27 73 views
-1

我们一直在团队中反复讨论各个开发人员使用功能分支,重新定义等的最佳流程。以下是我们提出的(来自一些邮件列表),但似乎有点复杂&有很多步骤。还有其他的SO问题与一些似乎相似和简单的答案例子。功能分支的好git过程

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

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

这几乎是 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严重错误,您可以使用reset回滚。

+0

但是你可以回滚一个rebase,只需重新设置refs即可。 'git checkout -B master master @ {1}; git checkout -B develop develop @ {1}'完成。你已经回滚了你的rebase。查看'man gitrevisions'和'man git reflog',你可以在至少最近90天内重置ref。 – jthill

+0

是的,你可以做到这一点,但我的方式基本上用友好的名字标记,你可以很容易地找到它。 – ams