简体   繁体   English

Git分支帮助/建议

[英]Git Branching Help/Advice

I think I'm not quite grasping the reason behind branches in Git. 我认为我不太了解Git中分支机构的原因。

I'm developing an application which makes use of a framework. 我正在开发一个使用框架的应用程序。

Could I run two branches one with the app and another branch for the framework? 我可以运行两个分支,一个与应用程序一起运行,另一个与框架一起运行吗? Or should I branch away when I want to update the framework, fix any possible bugs and then merge it back in? 还是当我想更新框架,修复任何可能的错误然后合并回去时我应该分支吗?

Thanks! 谢谢!

Branches are for organizing different aspects of development on a project. 分支机构用于组织项目开发的不同方面。

For example: You have your framework working. 例如:您正在使用框架。 You decide that you want to reorganize the code for a new feature or want to work on a feature that you aren't sure about releasing. 您决定要重新组织新功能的代码,或者要使用不确定要发布的功能。 So you create a branch and work on it there. 因此,您创建了一个分支并在那里进行处理。 Meanwhile, you find that your framework has a bug in it. 同时,您发现您的框架中存在错误。 You are able to go back to the original branch, create the bug fix and release that. 您可以返回到原始分支,创建错误修复程序并将其发布。

You can have multiple avenues of development going on at the same time keeping them separate until you are ready to do something with them. 您可以同时进行多种开发,直到您准备好对它们进行处理为止。

The use case that you are talking with an app and a framework would be to have seperate repositories for those. 您正在与应用程序和框架进行通信的用例是为这些应用程序和应用程序提供单独的存储库。 Rather than branching. 而不是分支。

Look into submodules... you could submodule the framework to keep it separated from your application code. 查看子模块...您可以将框架子模块化,以使其与应用程序代码分离。

Branches are generally used for features... so any time you are creating a new piece of functionality or fixing a bug you might create a branch to work on the feature/bug and then you would merge it into your master branch when you are done. 分支通常用于功能...因此,每当您创建新功能或修复错误时,都可以创建一个分支来处理功能/错误,然后在完成后将其合并到主分支中。

You would then also create a new branch when it comes time to update the framework submodule. 然后,当需要更新框架子模块时,您还将创建一个新分支。

If you want to make it so changing a skeleton framework can be easily merged back into the project, you have the idea almost right. 如果您希望这样做,那么可以轻松地将骨架框架的更改合并回项目中,那么您的想法几乎是正确的。

It's not the framework that should be branched away from your project, but your project should be branched away from your framework. 不是应该从项目中分支出框架,而是应该从您的框架中分支出项目。

And what you would do is any time you're developing something specific to your project, make the changes on your project path, and if you're developing something for the general framework, you make those changes on the framework branch. 而且,您要做的就是只要您在开发特定于项目的项目,在项目路径上进行更改,并且如果您正在为通用框架开发项目,则可以在Framework分支上进行更改。

And if you want to update your project to use the latest version of your framework, then on your project branch, just merge with the commit you feel is most stable on the framework branch. 而且,如果您要更新项目以使用最新版本的框架,则在项目分支上,只需与您认为在框架分支上最稳定的提交合并即可。

You can keep doing this over and over again, updating your project to use the latest version of the framework, keeping your framework branch separate and reusable for other projects. 您可以一遍又一遍地执行此操作,更新项目以使用最新版本的框架,使框架分支保持独立,并可用于其他项目。

Warning: never be on your framework branch and merge with your project. 警告:切勿位于框架分支上并与项目合并。 Only do it the other way around. 只能反过来做。

Here is a Git workflow that works great for me and really cemented the idea of branching into my head. 是一个Git工作流程,它对我来说非常有效,并且确实巩固了进入我的头脑的想法。

Basically, you have 2 main branches(master, develop). 基本上,您有2个主要分支(master,develop)。 From each of these, you can create a new sub-branch to work on features, bugs/hotfixes, etc.. 通过这些,您可以创建一个新的子分支来处理功能,错误/修补程序等。

This allows you to keep a clean master(live) version of your application that you can apply hotfixes to, as well as merge those hotfixes back into your develop and develop sub-branches once those hotfixes are ready. 这使您可以保留可以应用此修补程序的应用程序的干净的主(实时)版本,并在准备好这些修补程序后将这些修补程序合并回您的开发和开发子分支中。

There's quite a few other benefits to this workflow - noted in the article. 该工作流程还有很多其他好处-如本文所述。

There's also a Git plugin that makes using this workflow a bit simpler. 还有一个Git 插件 ,使使用此工作流程更加简单。

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

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