Skip to content

Instantly share code, notes, and snippets.

@mhart
Created December 11, 2012 04:16
Show Gist options
  • Save mhart/4255836 to your computer and use it in GitHub Desktop.
Save mhart/4255836 to your computer and use it in GitHub Desktop.
Script to fixup/squash commits given on a cmd line - can be used as a Custom Action in SourceTree
#!/bin/bash
lastCommit=""
editorCmd="sed -i ''"
for commit in $@; do
lastCommit=${commit:0:7}
editorCmd="$editorCmd -e 's/pick ${lastCommit}/fixup ${lastCommit}/'"
done
GIT_SEQUENCE_EDITOR=$editorCmd git rebase -i ${lastCommit}~2
@mhart
Copy link
Author

mhart commented Dec 11, 2012

Can be used like this:

git-fixup.sh af363a0ead31 7574fdbb9382ac3 118de7faa1e0a0

This will squash each of the given commits into its parent - useful to clean up bug-fix/syntax/reformatting/etc commits

@mhart
Copy link
Author

mhart commented Dec 11, 2012

To setup as a Custom Action in SourceTree, go to Preferences->Custom Actions:

  1. Click Add
  2. Menu Caption: fixup
  3. Script to run: [path to git-fixup.sh]
  4. Parameters: $SHA

You can then select a range of commits, right-click and choose Custom Actions->fixup to squash all of the given commits with their parents

@adamwong246
Copy link

Excellent! Now if only Source Tree would allow you to pass a new commit message to apply to the squashed commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment