Let's say I have a particular commit (for example, a gerrit patchset), with a whole bunch of merging history. I want a single commit of all its changes against master, without having to walk through a huge rebase of the intermediate commits.
First let's get it as a branch:
~/src/grot/gerrit-pull 6225/9
git checkout -b gerrit
Now, let's start a new branch from the current master:
git checkout master
git checkout -b tmp
The trick now is to totally reset the current staged set of changes to whatever the exact difference between 'tmp' and 'gerrit' is, ignoring all the commit history:
git checkout gerrit .
git commit -m 'your single commit'
Note that "." is necessary: git checkout
can mean both "switch branch" as well as
"reset the current cached changes". Wonderful stuff there git
. This will give us:
* commit 391e1c6cc417f09dab72d841b83d82a96fe877d5 (HEAD -> tmp)
| Author: John Levon <[email protected]>
| Date: Thu Jun 27 11:43:21 2019 +0000
|
| your single commit
|
* commit f38f9bbd3eb3e1c313f818381d65274846d40485 (master)