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.
The main difference between the case described in the article and my
repository is, that my master branch has existing branches. I would
like to keep the layout of those branches and their branch-points
equivalent after I have cut away the history.
- How do I get a “Github bare” repo with wget
- Leaving Github, how to change the origin of a Git repo?
- How to undo a git merge squash?
- Merging after directory got turned into submodule
- Getting the hang of git workflow for a small team
- Git: merge only the changes made on the branch
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. I don’t want to just
replay all branches on the new master, because that would possibly
Is there any smart and hopefully automatic way to do this?
One Solution collect form web for “Rebasing a branch that has been branched from”
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/. If
you have any grafts or replacement refs defined, running this command
will make them permanent.