本文介绍了Git实验分支还是单独的实验存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Android应用程序,并且在整个开发周期中一直在使用Git.现在,我想构建并发布实验性功能,供人们试用和安装,同时仍将原始,稳定的应用程序安装在他们的设备上.

I'm developing an Android application and have been using Git throughout the entire development cycle. I've now come to a point where I would like to build and release experimental features for people to try out and install, while still having the original, stable, application installed on their devices.

现在,这意味着我需要使用不同的包名称,这将更改开发项目中的一些基本文件.我还希望有一个单独的图标,以清楚地区分应用程序.

Now, this means I need to use a different package-name, which changes a few fundamental files in the development-project. I'd also like to have a separate icon to clearly differentiate the applications.

我不习惯Git,不知道该怎么做:我应该创建一个实验分支,当我想做一些实验工作时该分支从我分支出来,还是将这个实验工作作为单独的git保留? -回购?

I'm not used to Git enough to know which way to take here: Should I create an experimental branch which I branch off of when I want to make some lab-work or do I keep this experimental work as a separate git-repo?

无论哪种方式,我的实际流程都存在一些问题.

I have a couple of problems with the actual flow of going either way.

  • 如果我进行实验性分支,我不想(错误地)将软件包名称的更改和明确分开的实验性细节与master分支合并;我只想合并代码的工作部分,而无需进行额外的修改.
  • 如果我做一个单独的仓库,考虑到不希望替换的相同愿望,我该如何合并从实验仓库到主仓库的变更.包名称和图标?

推荐答案

这正是分支的目的.一个限制是git真正看到的是提交,而不是文件.因此,通常您可以使用cherry-pick命令将来自不同分支的一个或几个提交合并回master.

That's exactly what branches are for. The one limitation is that git really sees commits, not files. So you typically would merge back one or a few commits from a different branch into master using the cherry-pick command.

git branch branchx
git checkout branchx
... do work, commit (into branchx), repeat...
git checkout master   # return to master
git log branchx  # to find out the ID of the commit to merge back
git cherry-pick <commit ID from branchx>

这是首选方法.这意味着在实验分支中工作时应牢记这一点.您的提交应足够小,以仅包含修订/功能中涉及的文件.

That's the preferred approach. This implies that you should keep this in mind while working in your experimental branch. Your commits should be small enough to include only the files that are involved in a fix/feature.

或者,您可以选择一些文件以使用合并回来

Alternative, you can pick some files to merge back using

# from branch master do
git checkout branchx file1 file2 file3

查看此相关答案如何将选择文件与git-merge合并?

这篇关于Git实验分支还是单独的实验存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 03:39