删除/隐藏git分支而不删除提交历史记录 [英] Remove/hide git branches without deleting commit histories

查看:165
本文介绍了删除/隐藏git分支而不删除提交历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主开发分支和大量实验分支从其发芽(例如, exp1 exp2 )。这些实验分支的目的是作为产生数值结果的实验​​的占位符。我记录了实验分支的分支名称(和提交ID),这样我就可以返回到提交,以精确地查看结果背后的代码和历史记录。



但是,现在,有太多的实验分支,很难看到主树。所以,我正在重新思考我的策略,即让占位符保留每组结果背后的代码(即每个实验)。很明显,我可以保存每个分支的工作目录,但保留提交历史记录也很好。



可能的解决方案:



处理这个问题的一个方法是将实验分支移动到它们自己的独立回购站中,每个回收站都根据dev的提交历史记录中的相应节点的子节点科。下面是我的意思的例子:





点击此处查看大图的图片(在imgur.com上)。



因此,例如,对于分支 exp1 ,我想导出提交 A-> B-> C 到根据提交 A 的独立回购。然后,我可以记录提交 P1 的散列,以便知道 exp1 分支从哪里下降。 p>

问题:



我该怎么做?



更好的问题:

另一方面,我强烈怀疑有更好的策略来做什么我想要做的事情是,即整理目视检查树,但将占位符留给先前的分支,以便我可以根据需要返回给他们。所以,任何人都可以推荐一个这样的策略? 解决方案

以下是一个备选方案:使用非分支引用来保存分支提示因为这些是非分支引用,它们不会出现在 git branch 输出,也不在 git log --branches gitk --branches 中显示的内容。但是,它们将显示在 - 所有列表中,并将保留资源库对象。



创建或更新一个非分支引用,使用 git update-ref 。在 refs / 中选择一个名称空间,您认为它不会与将来的某些用途相冲突(当前的用途是 refs / heads / refs / tags / 对于标签,对于远程分支, refs /远程/ refs / notes / 为笔记, refs / stash 为存档)。


Situation:

I have a main repo with a main dev branch and lots of "experiment" branches sprouting off from it (e.g., exp1 and exp2). The purpose of these experiment branches is to serve as placeholders for experiments that generate numerical results. I record the branch name (and commit ID) of the experiment branches so I can return to the commits to see precisely the code and history behind the results.

But, now, there are so many experiment branches that it's getting hard to see the main tree. So, I'm rethinking my strategy for keeping placeholders to the code behind each set of results (i.e., each experiment). Obviously I could just save the working dir at each branch, but it would be nice to keep the commit history also.

Possible solution:

One way to deal with this is to move the experiment branches into their own independent repos, each being rooted at the child node of the appropriate node in the commit history of the dev branch. Here's an illustration of what I mean:

Click here for larger version of image (on imgur.com).

So, for example, for branch exp1, I would like to export commits A->B->C to a separate repo rooted at commit A. Then, I can just record the hash of commit P1 so that I know where the exp1 branch descended from.

Question:

How can I do that?

Better question:

On the other hand, I strongly suspect there is a much better strategy for doing what I want to do---namely, unclutter the tree for visual inspection but keep placeholders to prior branches so I can return to them if needed. So, can anyone recommend a strategy for this?

解决方案

Here's one alternative: use non-branch references to save the branch-tips before deleting the branch names.

Since these are non-branch references, they won't show up in git branch output, nor in stuff shown by git log --branches and gitk --branches, for instance. However, they will show up in --all listings, and will retain repository objects.

To create or update a non-branch reference, use git update-ref. Choose a name-space within refs/ that you think will not collide with some future use (current uses are refs/heads/ for branches, refs/tags/ for tags, refs/remotes/ for remote branches, refs/notes/ for notes, and refs/stash for the stash).

这篇关于删除/隐藏git分支而不删除提交历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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