简体   繁体   中英

Git config file local variables

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM