Skip to content

Instantly share code, notes, and snippets.

@rudle
Created February 17, 2015 02:44
Show Gist options
  • Save rudle/6c3561997f8f15a29f57 to your computer and use it in GitHub Desktop.
Save rudle/6c3561997f8f15a29f57 to your computer and use it in GitHub Desktop.
git-fixup
#! /usr/bin/env ruby
staged_files = Array(`git diff --name-only --cached`.split("\n"))
puts "staged files are: #{staged_files}"
staged_files.each do |file|
sha_to_fixup = `git log -n1 --format=%h #{file}`.gsub(/\s*/, '')
# assert sha has not been merged
fail "no commit to fixup in this topic branch" if `git branch --contains #{sha_to_fixup}`.split("\n").any? { |branch| branch =~ /\s*master\s*/ }
puts sha_to_fixup
`git commit --fixup #{sha_to_fixup}`
`git stash`
exec("git rebase -i --autosquash #{sha_to_fixup}^")
`git stash pop`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment