Created
February 17, 2015 02:44
-
-
Save rudle/6c3561997f8f15a29f57 to your computer and use it in GitHub Desktop.
git-fixup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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