如何正确使用git和分支 [英] How to properly use git and branches

查看:113
本文介绍了如何正确使用git和分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对GIT的版本控制很陌生。我阅读了这篇指南,并遵循了以下所示的基本方法图 HERE 。不过,我对如何使用git分支从现有代码中分离新功能的开发方面存在一些疑问。



下面是一个例子。假设在开始时,我的存储库包含以下两个主要分支:
$ b


  • 主分支(包含发行版本)

  • 开发分支(包含新的修补程序或功能将它们与现有项目功能分开)


当我需要开发新功能或模块,我从Develop开设分支并在那里开始新的代码项目。例如,我创建了三个新分支来添加与 Sun Star 相关的功能。超新星。现在,我的存储库包含五个分支:
$ b


  • 主分支:发布1.0.0

  • 开发分支:在版本1.0.0之后修改

  • NewModule_Sun分支:将Sun添加到项目中(从Develop分支创建)
  • NewModule_Star分支:将Star添加到项目从开发分支创建)


  • $ b

  • 新增模块_SuperNova分支:将SuperNova添加到项目p>对于版本1.0.1,我希望包含 Sun Star 模块,但不包含超新星。因此,我将它们与Develop合并,然后将Develop与版本合并:
    $ b


    1. 将NewModule_Sun合并为Develop

    2. 将NewModule_Star合并为Develop

    3. 将合并到Master(版本1.0.1)中

    Develop分支需要永久保存,但不再需要 Sun Star 分支。它们被删除:
    $ b


    1. 删除NewModule_Sun分支

    2. 删除NewModule_Star分支

    完成这些更改后,我的存储库包含以下三个分支:


    • Master Branch:Release 1.0.1
    • 开发分支:1.0.1后的修改

    • NewModule_SuperNova分支:1.0.0之后的修改来自Develop,当它不与Star / Sun分支合并时)



    ==


    $ b $首先,我是否正确地使用git分支?

    其次,我回顾了最终的Develop分支的历史,似乎我已经丢失了一些关于 NewModules 。这是正常的吗?而且,是否有可能将所有历史信息传输到Develop分支?



    谢谢!!

    解决方案


    我是否使用git?

    是的,您描述的工作流程非常标准化。你创建了一个分支,你可以在它上面工作,当你完成后,你合并它并删除不需要的分支(除非你要继续在那个分支上开发)。

    < blockquote>

    删除分支后,查看历史记录,在我看来,
    已经丢失了有关分支本身的所有信息......这是正常的吗?


    是的,这是正常的。


    留下的历史信息
    不间断?


    不确定这里是什么意思。只要你在删除它之前合并了分支,历史依然存在。您将它合并到另一个分支中,并且可以在该分支上看到历史记录。没有办法知道分支何时被删除,如果这是你要求的。


    I'm kind of new to version control with GIT. I read this Guide and am following the basic approach that is shown in the diagram HERE. Still, I have some doubts about how to use git branches to separate the development of new features from existing code.

    Here is an example. Suppose that at the start, my repository contains the following two main branches:

    • Master branch (containing the release version)
    • Develop Branch (containing new fixes or features to separate them from existing project features)

    When I need to develop new features or modules, I create branches from Develop and start the new code projects there. For example, I make three new branches to add features related to Sun, Star, and SuperNova. Now, my repository contains five branches:

    • Master branch: Release 1.0.0
    • Develop branch: Modification after release 1.0.0
    • NewModule_Sun branch: add Sun to project (create from Develop branch)
    • NewModule_Star branch: add Star to project (create from Develop branch)
    • NewModule_SuperNova branch: add SuperNova to Project (create from Develop branch)

    For Release 1.0.1, I want to include the the Sun and Star modules, but not SuperNova. So, I merge them with Develop and then merge Develop with the Release:

    1. Merge NewModule_Sun into Develop
    2. Merge NewModule_Star into Develop
    3. Merge Develop into Master (release 1.0.1)

    The Develop branch needs to be kept permanently, but the Sun and Star branches are no longer needed. They get deleted:

    1. Delete the NewModule_Sun branch
    2. Delete the NewModule_Star branch

    After these changes my repository contains the following three branches:

    • Master Branch: Release 1.0.1
    • Develop Branch: Modification after release 1.0.1
    • NewModule_SuperNova branch: Modification after release 1.0.0 (created from Develop when it was not merged with the Star/Sun branches)

    ==

    Firstly, am I using git branches correctly?

    Secondly, I reviewed the history of the final Develop branch, and it seems that I have lost some information on the NewModules. Is that normal? And, is it possible to transfer all the history information to the Develop branch?

    Thank you!!

    解决方案

    Am I doing a propery use of git?

    Yes the workflow that you describe is pretty much standard workflow. You create some branch, you work on it and when you're done you merge it and remove the not needed branch (unless you are going to continue developing on that branch).

    After removing a branch, viewing the history it seems to me that I have lost every information about the branch itself... is that normal?

    Yes this is normal.

    is it possible to remove a branch but leaving the history information unbroken?

    Not sure what you mean here. As long as you have merged the branch before deleting it, the history is still there. You just merged it into another branch and the history can be seen on that branch. There is no way to know when a branch was deleted if that's what you are asking for.

    这篇关于如何正确使用git和分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆