Search code examples
gitgit-config

Show the full command when executing a Git alias?


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)


Solution

  • 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' -"