UPDATED RESPONSE
Some time ago, a new argument --fixup was added to git commit , which can be used to build a commit with a log message suitable for git rebase --interactive --autosquash . So, the easiest way to fix a past commit is:
$ git add ...
ORIGINAL RESPONSE
Here is a little Python script that I wrote some time ago that implements this git fixup logic that I was hoping for in my original question. The script assumes that you have made some changes, and then apply these changes to the commit data.
NOTE : This script is for Windows; it searches for git.exe and sets the GIT_EDITOR environment variable using set . Adjust this as necessary for other operating systems.
Using this script, I can accurately implement the "fixed patched sources, phase fixes, run the git fixup workflow", which I requested:
#!/usr/bin/env python from subprocess import call import sys # Taken from http://stackoverflow.com/questions/377017/test-if-executable-exists-in python def which(program): import os def is_exe(fpath): return os.path.exists(fpath) and os.access(fpath, os.X_OK) fpath, fname = os.path.split(program) if fpath: if is_exe(program): return program else: for path in os.environ["PATH"].split(os.pathsep): exe_file = os.path.join(path, program) if is_exe(exe_file): return exe_file return None if len(sys.argv) != 2: print "Usage: git fixup <commit>" sys.exit(1) git = which("git.exe") if not git: print "git-fixup: failed to locate git executable" sys.exit(2) broken_commit = sys.argv[1] if call([git, "rev-parse", "--verify", "--quiet", broken_commit]) != 0: print "git-fixup: %s is not a valid commit" % broken_commit sys.exit(3) if call([git, "diff", "--staged", "--quiet"]) == 0: print "git-fixup: cannot fixup past commit; no fix staged." sys.exit(4) if call([git, "diff", "--quiet"]) != 0: print "git-fixup: cannot fixup past commit; working directory must be clean." sys.exit(5) call([git, "commit", "--fixup=" + broken_commit]) call(["set", "GIT_EDITOR=true", "&&", git, "rebase", "-i", "--autosquash", broken_commit + "~1"], shell=True)
Frerich Raabe Sep 30 '10 at 8:10 2010-09-30 08:10
source share