Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show the full command when executing a Git alias?

Tags:

git

git-config

Is there an option to show the full command when using an alias?

Example:

$ git ci -m "initial commit"
Full command: git commit -m "initial commit"
...
$ git lg
Full command: git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
...

Aliases are very convenient, but I like to learn/be reminded what my alias actually do (most of my aliases are copied from the Internet)

like image 760
john2x Avatar asked Jun 21 '12 09:06

john2x


People also ask

What is a git alias?

Git aliases are a powerful workflow tool that create shortcuts to frequently used Git commands. Using Git aliases will make you a faster and more efficient developer. Aliases can be used to wrap a sequence of Git commands into new faux Git command.

What command would create the My alias for the commit command?

To create this alias, just run this command: git config --global alias.


2 Answers

Another option is the command ideas listed in the Git wiki section on Aliases wich gives, for the alias section of .git/config

[alias]

    aliases = !git config --get-regexp 'alias.*' | colrm 1 6 | sed 's/[ ]/ = /'

This then lists all your aliases as command lines.

like image 124
Philip Oakley Avatar answered Oct 11 '22 08:10

Philip Oakley


As an example:

log-1 = "!sh -c 'echo \"Full command: git log --graph --decorate --pretty=oneline --abbrev-commit\"; git log --graph --decorate --pretty=oneline --abbrev-commit' -"

You call the shell and execute the given commands.

In your lg example, you would have to do a whole lot of escaping as you have quotes inside qoutes and characters that need to be escaped. I suggest you create your own pretty format and use that in the alias. Let;s assume we call your format mine. This is what you need to do:

git config --add pretty.mine "%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%C(bold blue)<%an>%Creset"

and the alias would be

lg = "!sh -c 'echo \"Full command: git log --graph --pretty=mine --abbrev-commit --date=relative\"; git log --graph --pretty=mine --abbrev-commit --date=relative' -"

like image 29
Peter van der Does Avatar answered Oct 11 '22 08:10

Peter van der Does