A variation of a question that has been asked multiple times but I haven't been able to determine a fitting answers that covers my case.
In short I want to rebase a repository without specific commits and preserve already done merge conflicts with minimal effort having a longer history.
I know there is Remove commit from history but it is not specific enough for my case. There the main point of this question of preserving already done merges and conflicts is not addressed at all.
git rebase -i
is not sufficient: merges and how they are handled should be preserved keeping a non-linear history.
While my questions is tightly related to single files, I want to clean commits and git-filter-repo
and git rm --cached
paired with just rebase
or reset
are too simple and not what is needed, the git history is not trivial.
That single files are involved should just make the process easier but does not make it trivial.
We want to remove several commits from our git history as if they have never been made (we do not just want to clean the files but the commits). Prerequisites:
The be best thing we found is git rebase -i master --rebase-merges
and do a label-onto and drop/remove the commits we do not want.
However this forces us to handle all merge conflicts that were solved in the past again. How can this be avoided, i.e. how can we make a copy if the repository without the commits we want to remove?
Keep a list of the files that you want to remove..... so that you can do something like git rm --cached the-list-of-doomed-files
at any point. You can do a git rebase interactive --rebase-merges
, and remove the commits of the files you want to get rid of.... then, when the rebase starts, and assuming all you want to do is just git rid of those files without additional changes, then you can safely run this every time you find a conflict:
git checkout REBASE_HEAD -- .
git rm --cached the-list-of-dommed-files
GIT_EDITOR=/usr/bin/true git rebase --continue
That should work, at least on paper.