Skip to content

Instantly share code, notes, and snippets.

@ptbrowne ptbrowne/
Last active Aug 29, 2015

What would you like to do?

git fix

Combines python-inquirer and git-amend-old to make git fix.

This gives you the possibility to amend a specific commit very easily.

Thanks to @magmax and @colinodell


Put the two files in your $PATH.

Then you will be able to do:

$ git fix

when you have staged some changes that you want to integrate to an older commit.


You will need to have python installed and the python libraries sh and inquirer to be installed.


This has not been tested thoroughly since it is merely a mashup of two tools, so use it as your own risks. git reflog might be your friend.

#! /usr/bin/env python
from sh import git
import inquirer
import sys
if __name__ == '__main__':
if len(sys.argv) < 2:
print "Usage: git choose-commit commit1..commit2 [filewheretosave]"
commits = git('--no-pager', 'log', '--no-color', '--oneline', sys.argv[1]).split('\n')[-2::-1]
questions = [
message="Which commit do you want to fix ?",
answers = inquirer.prompt(questions)
if len(sys.argv) > 2:
with open(sys.argv[2], "w+") as f:
print answers['commit'][:8]
#! /bin/sh
tempfoo=`basename $0`
TMPFILE=`mktemp /tmp/${tempfoo}.XXXXXX` || exit 1
git choose-commit '@{u}..HEAD' $TMPFILE
git amend-old $(cat $TMPFILE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.