Git internally is just a folder that contains objects that represent snapshots of the state of your files.
So the first step in the process is to copy your entire project including the .git
folder (this is crucial you may not see it if it hidden, but it will be okay if you just copy the all project folder).
The next step is to operate the git rebase
command in the copied folder like this:
git rebase -i <A hash in this exmple ce0e2fd>
You'll be presented with an interactive window like this:
ce0e2fd pick A initial commit
72ab3c4 pick B add stuff
8150939 pick C add big files
301c1e1 pick D add stuff
ab123c4 pick E remove big files
342d191 pick F add stuff
12ce3d7 pick G add stuff
23fd457 pick H add stuff
...
If you're using the default vim editor, you may need to learn how to use it, too.
My recommendation is to use vscode, use this tutorial to change it to your default editor.
Interactive rebase provides instructions for your scenario, so you should change "pick"
to "squash"
for A till E:
ce0e2fd squash A initial commit
72ab3c4 squash B add stuff
8150939 squash C add big files
301c1e1 squash D add stuff
ab123c4 squash E remove big files
342d191 pick F add stuff
12ce3d7 pick G add stuff
23fd457 pick H add stuff
This will squash A till E into a single commit, allowing you to change the commit message.
If you're happy to use the commit message of A, you can use "fixup"
instead of "squash"
and you won't be prompted to update the commit message.
In case you want to make sure that the commits A to E are completely removed and no longer accessible, please check
this answer on how to prune dangling commits.
update:
Base on the comments and our discussion, it seems you will maybe face some conflicts.
As well said @mat:
"but it ended up in merge conflicts" Why did it end? Merge conflicts only end things if you stop when you get them. Don't. The correct response to merge conflicts is to resolve them. Remember, merge conflicts are not bad. They are not an error condition. They are not a problem. They merely indicate that what's happened is beyond Git's capacity to perform automatic merge. Merge conflicts are a good thing: they greatly reduce the chances that Git will do something wrong while merging for you.