Disclaimer: You must first run a test repo, as the commands given here may destroy your data .
You can edit (i.e. edit a script) history through a quick export mechanism. The first step is to run git fast-export --signed-tags=strip --no-data --full-tree --export-marks=export.marks branch1 branch2 [...] branchN > commits.fi . Now you have a quick import of all your branches. In this thread, you can remove the commit by deleting the lines from commit refs / ... to the final new line. You also need to remove the lines from :<mark> line (as well as merge :<mark> if your new story begins with a merge) from your new "first" commit.
To help this process, you should study the revision graph and accept the changes when no merges cross their history. In the following graph, A, D, and F are good candidates to start. B or C have a problem that the successor of D also depends on G and A.
A ---- B ---- C ---- D --- E ---- F \ / \ \ / \--- G ------- H \--I--J-/
Using the export.marks file export.marks you can translate the commit identifier to mark numbers in the stream.
You need to give your branches new names, since git fast-import will not accept the new history, because new branches do not contain commits from existing ones.
After creating a new story, you need to import it using git fastimport < manipulated-history.fi into an existing repo.
Now it's time to check if the import is correct. To do this, you need to clone the repo into a temporary one, and in this temporary repo you create a graft for each newly created commit so that it has the same parent revisions as before. After that, you run git filter-branch newBranch1 newBranch2 [...] newBranchN . The import was correct if each newBranch now remains with the same message as the corresponding branch.
When everything works so far, you can create a new repo and pull the newBranch branches from the first working clone into it and make it a new working repo. Also note that you should not leave any transplant repositories anywhere, since transplants can be harmful .
source share