5

I'm using a little script to fix up past commits. The script assumes that the fix for the broken commit is staged, that the working directory is clean and that broken commit is passed on the command line. Here's the raw Python core of the script:

#!/usr/bin/env python import os import sys broken_commit = sys.argv[1] logmsg = os.popen( "git log --format=%%s %s~1..%s" % ( broken_commit, broken_commit ), 'r' ).read().strip() os.system( "git commit --message \"fixup! %s\"" % logmsg ) os.system( "git rebase --interactive --autosquash %s~2" % broken_commit ) 

At this point, I'm presented with an editor and just need to confirm (:wq in my case) the shown changes. How can I avoid this last step? I'd like the git rebase line to just go on without giving me the chance to edit the steps shown.

I heard you could have special script set via the EDITOR environment variable to achieve. However, I'm using msysGit on Windows, so I'm a bit limited in that area.

3
  • I was going to say, "Just leave off the --interactive", but that I read the documentation for autosquash: "This option is only valid when the --interactive option is used." Bummer. +1 for a good question! Commented Aug 23, 2010 at 15:32
  • Its probably very simple to add a --autoaccept option to git-rebase--interactive.sh if you want to give that a try. Commented Aug 23, 2010 at 17:09
  • @mathepic: Probably, but it seems wrong to have three switches --interactive, --autosquash and --autoaccept - and each of them only makes sense when the predecessor was specified. Commented Aug 25, 2010 at 8:01

2 Answers 2

7

Setting the environment variable EDITOR to true before running git rebase will make it accept the shown changes automatically.

Sign up to request clarification or add additional context in comments.

1 Comment

You could use GIT_EDITOR to keep from accidentally mucking anything else up, though it ought to be run in a subshell anyway, so moot point. You could also make this an alias: rbas = '!export GIT_EDITOR=true; git rebase --interactive --autosquash' or in the case of your python script, just set the environment variable in the same invocation of system as the call to git rebase.
0

If you want to make an alias on your file .gitconfig :

rb = '!export GIT_EDITOR=true; git rebase --interactive --autosquash' 

If you want to make an alias on your file .bashrc or .zshrc :

alias rb='export GIT_EDITOR=TRUE; git rebase --interactive --autosquash' 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.