Switch to a new branch (
git checkout -b experiment)git checkout -b experimentCommit the changes
Revert the changes†
Merge the branch into master, avoiding a fast-forward so that there will be an actual merge commit.
git checkout master git merge experiment --no-ff
The result will be this history:
... A ── B ──────────── C ── D ... ─master ╲ ╱ idea ── undo ─experiment Advantages:
- The addition and deletion are clearly grouped together, and can still easily be referenced.
- There is a continuous history skipping the whole experiment, with an empty diff between
BandC. - There are no unmerged branches to be kept around. The
experimentbranch can be deleted without losing the commits.
†In fact it's even possible to omit the undo commit, and instead merge from idea directly without actually including the changes. This would however be confusing, since it will look like the changes were taken into master and only the diffs would show they weren't.