2

This has intrigued me this morning when I attempted to set a git alias by using

git config --global alias.ac '!sh -c "git add . && git commit -m $0"'

But it failed to work after git ac "Finish static pages" due to the error

fatal: Option -m cannot be combined with -c/-C/-F/--fixup.

It still gives me a headache after searching around. Why can't I combine -m option with sh -c and how should I do correctly to make this work? Much appreciated!

Edit If I use

git config --global alias.ac '!sh -c "git add . && git commit -m $1"'

instead of $0 in the end, it will say

sh: git add -A ; git commit --message Finish static pages: No such file or directory
fatal: While expanding alias 'ac': 'sh -i "git add -A ; git commit --message $1"': No such file or directory

I think I am looking for a way to accept an string instead of single word argument, maybe?

donkey
  • 4,285
  • 7
  • 42
  • 68
  • I am pretty sure cause i reproduce the same issue everytime, now i try to use other flags, but certainly these others are even more wrong. – donkey Aug 12 '14 at 06:13

1 Answers1

1

Try using $1 instead of $0

git config --global alias.ac '!sh -c "git add . && git commit -m \"$1\""'

$0 would repeat the entire command in your commit message. Meaning, it isn't one of the positional parameters.
And you can try adding double quotes for the message: \"$1\"


Other options exist for that kind of alias: see "Git Alias - Multiple Commands and Parameters".
For example

git config --global alias.ac '!f(){ git add . && git commit -m "$1"; };f'
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250