How to remove selected commit log entries from a Git repository while keeping their changes?
commit, git
Solution
git-rebase(1) does exactly that.
$ git rebase -i HEAD~5
git awsome-ness [git rebase --interactive] contains an example.
- Don't use `git-rebase` on public (remote) commits.
- Make sure your working directory is clean (`commit` or `stash` your current changes).
- Run the above command. It launches your `$EDITOR`.
- Replace `pick` before `C` and `D` by `squash`. It will meld C and D into B. If you want to delete a commit then just delete its line.
If you are lost, type:
$ git rebase --abort
Problem
I would like to remove selected commit log entries from a linear commit tree, so that the entries do not show in the commit log. My commit tree looks something like: ``` R--A--B--C--D--E--HEAD ``` I would like to remove the B and C entries so that they do not show in the commit log, but changes from A to D should be preserved. Maybe by introducing a single commit, so that B and C become BC and the tree looks like. ``` R--A--BC--D--E--HEAD ``` Or, ideally, after A comes D directly. D' representing changes from A to B, B to C and C to D. ``` R--A--D'--E--HEAD ``` Is this possible? if yes, how? This is a fairly new project so has no branches as of now, hence no merges as well.