简体   繁体   English

使用git-flow,如何将rebase工作到混合中

[英]Using git-flow, how to work rebase into the mix

I'm brand-new to rebasing. 我是变革的全新品牌。 I'm used to the git-flow method, whereby I branch off our main/develop branch, do my work, open a pull request on github, and it's merged in and we move on. 我已经习惯了git-flow方法,我分支了我们的main / develop分支,完成我的工作,在github上打开一个pull请求,然后它就被合并了,我们继续前进。 Works well. 效果很好。

Others are doing rebasing however, and I'd like to try it out. 然而其他人正在进行变基,我想尝试一下。 I've read up on it ( here for instance) and while I get the idea, one bit confuses me. 我已经阅读了它(例如这里 ),当我明白这个想法时,有点让我感到困惑。

In git-flow, when I make my changes to my branch, I push that branch to the server and open a pull request. 在git-flow中,当我对分支进行更改时,我将该分支推送到服务器并打开pull请求。 In a rebase, per the link above, I'm told to Periodically rebase your feature branch onto the current state of the destination branch .. 在一个rebase中,根据上面的链接,我被告知Periodically rebase your feature branch onto the current state of the destination branch重新Periodically rebase your feature branch onto the current state of the destination branch

...and if I do that, what do I then push to github? ......如果我这样做,那我该怎么推到github? The branch I've based onto, ( develop in my case)? 我所依据的分支,(根据我的情况develop )? As a git-flow guy that feels weird to me but maybe that's because I'm not used to it. 作为一个对我来说感到奇怪的git-flow家伙,但也许那是因为我不习惯它。

If there are other ideas on how to mentally shift from git-flow to doing rebasing I'm glad to hear of it as well. 如果还有其他关于如何从git-flow转变为变革的想法,我也很高兴听到它。

Say your feature branch looks like this 假设你的功能分支看起来像这样

* -- * -- A (master)
           \
            * -- * -- * (feature)

After some time, others have done work on master so that the history becomes 过了一段时间,其他人已经完成了master工作,以便历史成为现实

* -- * -- A -- B -- C -- D -- E (master)
           \
            * -- * -- * (feature)

The only thing that rebasing feature on to master does is to change when it appears you created the feature branch: 对于master来说,唯一的变形feature是在创建feature分支时更改:

* -- * -- A -- B -- C -- D -- E (master)
                               \
                                * -- * -- * (feature)

By doing this periodically, you resolve any potential merge conflicts before they can pile up. 通过定期执行此操作,您可以在堆积之前解决任何潜在的合并冲突。 If you merge master into feature periodically, you end up with lots of spurious merge commits in feature . 如果您定期将master合并到功能中,则最终会在feature大量虚假的合并提交。 With rebase, you avoid them, with the price being that you lose sight of when you initially branched feature from master . 使用rebase,你可以避免它们,价格是当你最初从master分支feature时你看不到的。 Keep in mind that you should only rebase if you haven't already pushed feature ; 请记住,如果你还没有推你应该只重订feature ; once you do, you have shared the history of feature with others and should not change it. 一旦你这样做,你就已经与他人分享了feature的历史,不应该改变它。

To periodically rebase your feature branch onto the current state of the destination branch (I'm assuming origin/master in this scenario), just do this from your feature branch: 要定期将功能分支重新定位到目标分支的当前状态(我假设在此方案中为origin / master),只需从功能分支执行此操作:

git fetch origin            # Updates origin/master
git rebase origin/master    # Rebases current branch onto origin/master

An equivalent alternative: 等效替代方案:

git pull --rebase origin master

By doing so, you will keep your feature branch up to date with your origin/master branch. 通过这样做,您将使您的功能分支与原始/主分支保持同步。 You can either merge it into your local master and push into origin/master or you can just push your rebased feature branch to the remote repository and just do a pull request. 您可以将其合并到本地主服务器并推送到origin / master 也可以将您的重新定义的功能分支推送到远程存储库,然后执行pull请求。 It really depends on your git workflow. 这真的取决于你的git工作流程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM