Skip to content

[git] Using rebase to squash oops commits before pushing

Utumno edited this page Mar 1, 2014 · 2 revisions

Say I want to rebase wrinklyninja-bossv3-support to take the executables out - first I create a branch off it (in gitk most easily)

add branch in gitk

Then I issue git rebase -i HEAD~5. My editor opens and it contains:

pick 49e968d Installer script changes.
pick c72b46e Darn, added generated files by accident in last commit.
pick 96f2279 Fixed MSVC 2013 redist not being installed if missing.
pick ad954c4 Updated version history for 304.4.
pick 90f17f9 Fixed MSVC 2008 URL and download directories.

# Rebase 647a092..90f17f9 onto 647a092
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

Change to

pick 49e968d Installer script changes.
f c72b46e Darn, added generated files by accident in last commit.
pick 96f2279 Fixed MSVC 2013 redist not being installed if missing.
pick ad954c4 Updated version history for 304.4.
pick 90f17f9 Fixed MSVC 2008 URL and download directories.

save, exit the editor and let git squash the commits:

Welcome to Git (version 1.8.5.2-preview20131230)

MrD@MRSD /c/dropbox/eclipse_workspaces/python/git_svn_WB (b_Rebase_wrinklyninja-
bossv3-support)
$ git rebase -i HEAD~5
[detached HEAD 74f085c] Installer script changes.
 Author: WrinklyNinja <wrinklyninja1@gmail.com>
 1 file changed, 206 insertions(+), 254 deletions(-)
Successfully rebased and updated refs/heads/b_Rebase_wrinklyninja-bossv3-support
.

If the commit I wanted to squash was not directly after the one it should be squashed into, just place it there simply re-ordering the lines. Then I rebase over the branch I want to push (usually dev - see https://github.com/wrye-bash/wrye-bash/wiki/%5Bgithub%5D-Branching-and-merging-to-dev-using-rebase)

Clone this wiki locally