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.

Frerich Raabe
  • 90,689
  • 19
  • 115
  • 207
  • 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! – Daniel Stutzbach Aug 23 '10 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. – alternative Aug 23 '10 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. – Frerich Raabe Aug 25 '10 at 08:01

2 Answers2

6

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

Frerich Raabe
  • 90,689
  • 19
  • 115
  • 207
  • 3
    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. – Cascabel Aug 23 '10 at 16:07
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'
Jack'
  • 1,722
  • 1
  • 19
  • 27