Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Random thought: given you already have the gcaa alias, perhaps you could include a check that .git/REBASE_HEAD doesn't exist in that?

Probably easiest as a little shell function like

    gcca() {
      local GIT_DIR
      if ! GIT_DIR=$(git rev-parse --git-dir); then
        return 1
      elif test -f "$GIT_DIR/REBASE_HEAD"; then
        printf 'Rebase in progress: commit --amend is disabled\n' >&2
        return 1
      fi
      git commit -a --amend "$@"
    }
rather than an alias?

[Edit] I forgot about rev-parse --verify, which simplifies this further:

    gcca() {
      if git rev-parse --verify REBASE_HEAD >/dev/null 2>&1; then
        printf 'Rebase in progress: commit --amend is disabled\n' >&2
        return 1
      fi
      git commit -a --amend "$@"
    }
This also leaves you still able to use commit --amend long-hand if (for example) you want to edit one of your own commits during rebase -i.


Dude your "random thoughts" are better than a lot of folks' work output ツ


That's a great idea. Git problems are sorta in the category of problems I've avoided trying to solve because, can't solve everything, and I've been hacking around it successfully instead.


You can shorten `>/dev/null 2>&1` to `&>/dev/null`.


Unfortunately that's bash-specific I think: the POSIX shell spec still hasn't picked it up. (Though strictly speaking, my 'local' is out of spec too.)


Also works in Zsh. Can’t speak for other shells.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: