Search code examples
gitversion-controlcollaboration

Is there a way to remove "pointless" commits from git history?


Suppose I have a git history like this:

A-B-C-D-E-F-G

B added 60k files.

F removed those same files.

Any operation that traverses git history, such as git log, now takes a stupid amount of time if it has to cross F (or B).

Is there a way to effectively remove B and F from history, given that they simply cancel each other out?

More to the point: is there an easy way to do this, and then ensure that the other developers using the repo are also up to date? (Bear in mind said developers also have feature branches sitting on their machines.) I suspect all the solutions are going to end up resulting in A-C'-D'-E'-G'...

My gut says the best I'm going to get is to create a branch from A, cherry-pick C through E, then create a new branch from G, and merge that onto the first branch. Or something.


Solution

  • Just do git rebase -i A and remove the lines for B and F.
    But as you said (or meant), this will rewrite published history, so all your fellow developers need to rebase all their branches based off that manipulated branch like described in the man page of git rebase under the section "How to recover from upstream rebase".