To apply the extra parameters to anything except the end of your alias’ “command line”, you will need to put your shell commands in a script. You can do it with an external script (like jdelStrother’s answer), or you can do it with an “inline” shell script.
You can use -m
to feed git commit
your new message or use the -C HEAD
/--reuse-message=HEAD
option to have it use the existing message and author (it would also reuse the author timestamp, but you are resetting that with --date=…
). Using any of these options will prevent Git from opening an editor for your commit message.
Here it is as an “inline” shell script:
git config --global alias.sync '!sh -c '\''git commit --amend --date=today ${1+-m} "${1---reuse-message=HEAD}" && git rebase master'\'' -'
The core of this small script is the pair of conditional parameter expansions:
${1+-m} "${1---reuse-message=HEAD}"
When you call it with an extra parameter (i.e. your replacement log message), these expand to two shell words: -m "<your new log message>"
. When you do not supply the extra parameter, they expand to just a single word: "--reuse-message=HEAD"
.
The trailing dash is also important; it could be any shell word, the point is that something must be there because the shell will use it to initialize its $0
parameter (which usually has a default value, so it is useless for the conditional expansion itself).
If I misunderstood and you actually want to see the editor when you do not supply the extra parameter, then use the single expansion ${1+-m "$1"}
instead of the pair of expansions.