Git Alias for Message with Argument

113 views Asked by At

I am using msysgit to run Git on a Windows box and I'm interested in establishing an alias for a common task: committing.

In our environment, our messages need to follow a certain format: 'jira-BL-[TICKET_NUMBER]- [MESSAGE]'. For this alias, I'd like to parameterize the [TICKET_NUMBER] and [MESSAGE] parts to eliminate typos that break our build system, so I could call it like this:

git ca 1234 'Fixed bug'

Right now, I have this in my .gitconfig (based on some googling/experimenting):

ca = "!sh -c 'git commit -am 'jira:BL-$1 - $2''" -;

Which gets me an actual commit message of "jira:BL-1234" but the second part of the message is completely lost. I know that git can handle parameters on its own (without the shell call), but from what I've seen, it can't handle them in the way I'd like here. What am I missing or am I not going to be able to do this?

1

There are 1 answers

1
sehe On BEST ANSWER
ca = "!sh -c 'git commit -am \"jira:BL-$1 - $2\"'" -;

seems to be closer. I'm not sure I'd say this macro makes life easier :/

Perhaps you can select your favourite editor as the commit editor and make a macro/abbreviation there that does what you need