Last active
December 20, 2015 02:29
-
-
Save joequery/6056553 to your computer and use it in GitHub Desktop.
This script searches through the git log for the current directory you're in and starts an interactive rebase on a "base commit", which is simply a commit that doesn't start with "fixup! "
This file contains hidden or 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 python | |
| import subprocess | |
| p = subprocess.Popen(["git", "log", "--format='%s'"], stdout=subprocess.PIPE) | |
| out, err = p.communicate() | |
| # Keep going until we don't find a "fixup! " | |
| fixup_count = 0 | |
| max_list_size = 10 | |
| commits = out.split('\n')[:max_list_size] | |
| for c in commits: | |
| if "fixup! " not in c: | |
| break | |
| fixup_count += 1 | |
| head_str = "HEAD~%d" % (fixup_count + 1) | |
| print("Fixup count: %d" % fixup_count) | |
| if fixup_count == max_list_size: | |
| print("No base commit found in the last %d commits!" % max_list_size) | |
| print("You should REALLY consider rebasing...") | |
| elif fixup_count == 0: | |
| print("No fixup commits found. Nothing to do") | |
| else: | |
| print("Found base commit %d commits back: %s" % (fixup_count, c)) | |
| print("*** Calling interactive rebase on %s..." % head_str) | |
| subprocess.call(["git", "rebase", "-i", "--autosquash", head_str]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment