1

Here's a simple example to demonstrate my problem. If I do:

git commit -m "`date --utc`"

It executes date --utc, and puts the result inside the commit message.

However, when I alias it to testcomit:

git config --global alias.testcommit 'commit -m "`date --utc`"'

Doing git testcommit does not execute the `date --utc` part, it instead puts it verbatim in the commit message.

So, how do I get this alias to execute date --utc?

Saeb Amini
  • 23,054
  • 9
  • 78
  • 76
  • 2
    I *think* you can use `git config --global alias.testcommit '!git commit -m "$(date --utc)"'`. The trick is the `!`, which makes the whole alias a shell command (hence the `git` in there), read more [here](http://git-scm.com/docs/git-config). (`$()` instead of backticks is unrelated, but you should start using it.) But you do know the time of a commit is stored by default, so there's no reason to put it in the message? – Biffen Sep 28 '14 at 10:45
  • @Biffen thanks let me try that to see if it works. I do know about the time, this is just an example to demonstrate the problem. – Saeb Amini Sep 28 '14 at 10:52
  • @Biffen, amazing! it worked. Please put it as an answer and I will accept it. – Saeb Amini Sep 28 '14 at 10:55

1 Answers1

9

From the documentation:

If the alias expansion is prefixed with an exclamation point, it will be treated as a shell command.

So you can use:

git config --global alias.testcommit '!git commit -m "$(date --utc)"'

Note that you have to put git in there, since you're now specifying the whole shell command.

($() instead of backticks is unrelated, but it's better so you should start using it.)

Biffen
  • 6,249
  • 6
  • 28
  • 36