Skip to content

Instantly share code, notes, and snippets.

@ptbrowne ptbrowne/README.md
Last active Aug 29, 2015

Embed
What would you like to do?
git-fix

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

https://github.com/magmax/python-inquirer

https://github.com/colinodell/git-amend-old

Usage

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.

Requirements

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

Disclaimer

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]"
sys.exit()
commits = git('--no-pager', 'log', '--no-color', '--oneline', sys.argv[1]).split('\n')[-2::-1]
questions = [
inquirer.List('commit',
message="Which commit do you want to fix ?",
choices=commits,
),
]
answers = inquirer.prompt(questions)
if len(sys.argv) > 2:
with open(sys.argv[2], "w+") as f:
f.write(answers['commit'][:8])
else:
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.