Reputation: 4363
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?
Upvotes: 2
Views: 1149
Reputation: 1324535
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'
Upvotes: 1