English 中文(简体)
我怎么能够合并一个支部,使专题成为孤儿?
原标题:How can I merge a git branch so that topic commits are orphaned?
  • 时间:2012-01-13 09:30:22
  •  标签:
  • git

我仍然以吉特的一些更先进特点加快了。

鉴于以下历史,我如何清理专题分支,以便它们作为单一承诺出现在历史上?

[master] - - - - - - - C - - -
   
   [feature] - A - - B - - D -

理想的情况是,我要与D的[总理]重新建立基础,然后将[女性]并入[总理],使A和B成为孤儿。

我认为,我只能这样做:

$ git rebase master # on feature branch
$ git co master
$ git merge --no-ff feature

之后,消除孤儿的承诺

$ git gc --prune=now --aggressive

这在历史上仍然留下了A和B,而Am I失踪了什么?

最佳回答

如果你想要“使用”A、B和D,你就可以使用互动的重新基础。

如果您的职衔<代码>feature在master 上。 (在你发布<条码>git rebase Master后,本事务科):

git rebase -i master

然后,在编辑开放的档案中,将标题A和B的“条码”改为<条码>。 之后,Gite将把A和B号带入D,编辑将用所有qu承诺的信息播。

问题回答

If I redraw your diagrams to place the branch markers at the tip of the branch (which reflects the actual representation of branches) your original situation is:

o --- C (master)
 
   --- A --- B --- D (feature)

在与<代码>-无-ff合并后 如你所描述,你现在有:

o --- C ------------------ M (master)
                        /
         A  --- B  --- D  (feature)
   
    --- A --- B --- D

根据我的理解,现在请确保<代码>A,BD从您的存放处消失。 首先,我要说,我强烈建议你不要担心这些承诺。

However, if you really want to get rid of them, then you will have to make sure that they are truly unreachable, or git gc --prune=now --aggressive will not remove them. As it is, they will still be pointed to (at least) by the reflog for feature. There are various ways of expiring entries from the reflog, e.g. with:

git reflog expire --expire=now feature

... or a safer option should be to set the config variable gc.reflogexpireunreachable to now and expire the reflog:

git config gc.reflogexpireunreachable
git reflog expire feature

在这两种情况下,你需要再操作<代码>git gcprune=now——aggressive

However, to reiterate what I said above, I wouldn t do this - those commits aren t hurting anyone and the reflog is a valuable safety net when using git.

如果你想要把一个分支变成一个单一承诺,那么从主人那里可以做到:

git merge --squash feature
git commit

although IMHO being able to keep the individual commits on the branch intact is actually a good feature most of the time.

或者,您可使用“git rebase-i,将其全部承诺汇总起来,然后将qu结果合并为主。

Why would it remove A and B?

<代码>git rebase Master将使主人排在下,如果主人承诺的话,从特稿中产生的所有承诺将归主。 因此,请见A和B(实际为A和B)

And git gc doesn t have anything to do with what you see in the history. It removes dangling commits ( which can be A and B, but you have A and B in master now)

If you want them to come as single commit, try the --no-commit option or look at other alternatives like git rebase -i ( and squash)





相关问题
git confusion - cloning a repo is returning a past version

Im having some confusion with my git usage. I cloned a repo from one comp to the other, and the new clone is the state of the original that was active some time ago. So its cloning a past version. ...

Appropriate strategy for tagging and hotfixing with git

I was wondering if the strategy I m using for tagging and hotfixing tags (which then I use for deploying rails applications) with git is appropriate. For tagging I just tag a commit of the master ...

Tips on upgrading CVS to git/hg?

We still use CVS, I use git and hg for my personal use though I m still a novice at both, but I realize they re much more modern and better, faster, distributed, etc. It s just everyone is so ...

Using Git in a TFS shop

Using Git at home has spoiled me - I now find using TFS at work to be a bit of a drag and want to explore the possibility of using Git locally and syncing somehow with TFS. I figure there are a few ...

热门标签