Question

I have a set of aliases for different type of logs, like:

lg = log --graph --pretty=format:'%C(cyan)%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(red)<%an>%Creset' --abbrev-commit --date=relative
unreleased = !git --no-pager log --graph --pretty=format:'%C(cyan)%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(red)<%an>%Creset' --abbrev-commit --date=relative release..master

There are many type of log aliases, but most of them share the same format. How can I define a local variable with the content of the common parts?

Ideally, I would like to avoid using an environment variable for that

Was it helpful?

Solution

As per this question, git-config doesn’t support expansion of variables. What you can do, however, is define an alias with the common parts:

lg = log --graph --pretty=format:'%C(cyan)%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(red)<%an>%Creset' --abbrev-commit --date=relative

Then define further aliases as shell commands that use the common alias:

unreleased = !git --no-pager lg release..master

Incidentally, specifying --date=relative has no effect, since %cr in your log format is by definition a relative date. This also means that --date=short, for example, would have no effect. You’ll need to use %cd instead if you want any of your other aliases to be able to change the date format.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top