如何使用git同时处理几个不同版本的文件? [英] How to work simultaneously on several different versions of files with git?

查看:221
本文介绍了如何使用git同时处理几个不同版本的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究一个我自己的神经影像工具箱,该工具箱在MATLAB / SPM8下运行,并且我的存储库中的大多数程序文件都是MATLAB *。m 文件。我有不同的功能分支和一个分析分支,用于使用当前版本进行分析。与此同时,我正在开发 master 和特性分支中的代码,然后不断合并到 master 分支中。



现在问题在于,我在分析分支中运行的分析需要花费很多时间(甚至几天),在此期间,我无法 git checkout master git checkout new-feature 。这严重限制了我的生产力。

因此,由于无法同时打开多个分支,
我正在考虑将 analysis 从开发存储库分支到它自己的存储库。问题是,如果我 git init 基于当前分析分支的新存储库,有没有办法以某种方式从开发库的当前 master 分支以某种方式 code> git merge ,以便能够使用新开发的我的开发仓库的代码在新的分析仓库中?

解决方案

如果你 git clone 将你现有的版本库加入到一个新的版本库中,然后你可以将 git push git fetch 以匹配你已经改变的参考(分支);不涉及合并。如果您使用 - mirror ,则会自动将硬盘中的内容硬链接以节省磁盘空间。 >选项添加到 git clone git push ,您将省略远程追踪分支并且只有相同的分支两者都更简单,更对称,但较少使用传统的git。为了最大化遵循教程的简单性,请安排第三个中央存储库(应该创建 - bare ),这两个工作存储库都是克隆的。 / p>

应该要求没有合并(除了快进合并,它们不是真正的合并,而是用新的后代替换旧的分支头),因为你在同一个分支上工作;你只需要两份。当您的分析完成并且您可以更新分析分支时,只需在分析 git merge --ff-only master $ C>;您可以在任何一个方便的存储库中执行此操作,但不要忘记将更改与 git push other-repository 同步。






另一个选项(自Git版本2.5以来)是 git worktree 命令,该命令允许多个独立工作树,您可以在其中 git checkout 等等。这与上述选择制作克隆的区别在于,这里只有一组分支

然而, 2.8)这仍然被认为是实验性功能,我没有亲自用它来评论它的可靠性和实用性。


I'm currently working on a my own neuroimaging toolbox that runs under MATLAB / SPM8 and most program files in my repository are MATLAB *.m files. I have different feature branches and one analysis branch, that I use for ongoing analyses using the current version. At the same time I am developing the code in master and feature branches, that are then constantly merged to master branch.

Now the problem is that, the analyses I'm running in analysis branch do take a lot of time (even days), and during that time I'm not able to git checkout master or git checkout new-feature. This limits my productivity seriously.

So, as it's not possible to keep several branches open at the same time simultaneously, I'm thinking to move the analysis branch out of the development repository to its own repository. The question is, that if I git init a new repository based on the current analysis branch, is there a way to somehow git merge every now and then from current master branch (of the development repository) to be able to use newly developed code of my development repository in the new analysis repository?

解决方案

If you git clone your existing repository into a new repository, you can then git push or git fetch from one to the other to match up the refs (branches) you've changed; no merges are involved. The contents of the repository will be automatically hard-linked to save disk space.

If you use the --mirror option to git clone and git push, you will omit having remote-tracking branches and just have the same branches in both, which is simpler and more symmetrical, but less of a conventional use of git. For maximal "follow the tutorials" simplicity, instead arrange a third "central" repository (which should be created --bare) which both of your working repositories are clones of.

No merges (other than "fast-forward merges" which aren't really merges, but replacing an old branch head with a newer descendant of it) should be required, because you are working on the same branches; you just have two copies of them. When your analysis is complete and you are able to update the analysis branch, just git merge --ff-only master while in analysis; you can do this in whichever repository is convenient, but don't forget to sync the changes back with a git push other-repository.


Another option (since Git version 2.5) is the git worktree command, which allows multiple independent working trees in which you can git checkout, etc., independently. The difference between this and the above option of making a clone is that here there is only one set of branches.

However (as of version 2.8) this is still considered an "experimental" feature, and I have not personally used it to comment on its reliability and usefulness.

这篇关于如何使用git同时处理几个不同版本的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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