简体   繁体   English

重新分支已分支的分支

[英]Rebasing a branch that has been branched from

I'm attempting to cut off a part of the history of a repository so I can graft it back onto the repository with git replace as described in this article . 我试图切断一部分存储库的历史记录,以便按照本文所述使用git replace将其嫁接到存储库中。

The main difference between the case described in the article and my repository is, that my master branch has existing branches. 本文中描述的案例与我的存储库之间的主要区别在于,我的master分支具有现有分支。 I would like to keep the layout of those branches and their branch-points equivalent after I have cut away the history. 在删除历史记录后,我想保持这些分支的布局及其分支点的等效性。

My history approximately looks like this 我的历史大概是这样的

    cut here
      |
      v
o--o--o--o--o--o--o master
            \  \  \
             \  \  o--o   A
              \  o--o--o  B
               o--o--o    C

There are no branches off of master before the "cut here" commit. 提交“此处剪切”之前,没有任何分支脱离主分支。

What I want to achieve is this: 我要实现的是:

o--o--o history

initial tree at cut
        |
        v
        o--o--o--o--o master
               \  \  \
                \  \  o--o   A
                 \  o--o--o  B
                  o--o--o    C

That means it wouldn't be sufficient to just rebase master on the initial tree but I also need to replay all existing branch on their equivalent new commit after the rebase of master. 这意味着仅在初始树上重新建立master的基础是不够的,但是我还需要在master的基础上重新对所有现有分支进行等效的新提交重播。 I don't want to just replay all branches on the new master, because that would possibly have conflicts. 我不想只重播新主服务器上的所有分支,因为这可能会有冲突。

Is there any smart and hopefully automatic way to do this? 是否有任何智能且希望自动执行此操作的方法?

These commands will have the result you are looking for: 这些命令将为您寻找结果:

git checkout --orphan temp-branch CUT–COMMIT
git commit // This will create your new initial commit
git rev-parse HEAD // To get the SHA of this commit
git replace CUT-COMMIT NEW-COMMIT
git filter-branch -- --all

If you have any question regarding to how and why this works, feel tree to leave a comment. 如果您对如何以及为什么这样有疑问,请留下评论。 You might want to backup your repo before you do stuff like this. 您可能需要先备份存储库,然后再执行此类操作。

From the filter-branch docu : 过滤分支文档中

NOTE: This command honors .git/info/grafts and .git/refs/replace/. 注意:此命令支持.git / info / grafts和.git / refs / replace /。 If you have any grafts or replacement refs defined, running this command will make them permanent. 如果定义了任何嫁接或替换引用,则运行此命令将使它们永久化。

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

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