Search code examples
gitgit-rebasesquash

Combine or rebase an arbitrarily large number of commits


Let's say my local git log shows:

739b36d3a314483a2d4a14268612cd955c6af9fb a
...
c42fff47a257b72ab3fabaa0bcc2be9cd50d5c89 x
c4149ba120b30955a9285ed721b795cd2b82dd65 y
dce99bcc4b79622d2658208d2371ee490dff7d28 z

My remote git log shows:

c4149ba120b30955a9285ed721b795cd2b82dd65 y
dce99bcc4b79622d2658208d2371ee490dff7d28 z

What's the easiest way to get to this (assuming an arbitrarily large number of local commits):

527b5810cfd8f45f18ae807af1fe1e54a0312bce a ... x
c4149ba120b30955a9285ed721b795cd2b82dd65 y
dce99bcc4b79622d2658208d2371ee490dff7d28 z

Solution

  • One option is git rebase -i @{u}. I use this frequently enough that I've aliased it as git freebase (since it works on the commits that you can freely rebase).

    In case you're not familiar, @{u} is a shortcut for @{upstream}, or "the upstream of the current branch".