search

Home  >  Q&A  >  body text

How to set alias with parameters in git

When setting alias in git, how to set the command with parameters?
For example, I have the command:
git log --all | grep "parameters"
My existing alias method is:
alog = log --all
When used, it is:
git alog | grep "parameters"
I want to know if there is a better way, you can merge grep into the alias, so that When using it, you only need to enter the
alias parameter?

PHP中文网PHP中文网2734 days ago1024

reply all(2)I'll reply

  • 世界只因有你

    世界只因有你2017-06-07 09:25:40

    The alias of git can only be set in git. prep is not a git command, so it will not work.

    If you need to use this command, you can set a shell alias.

    For example

    glag = git log --all | grep
    

    When using

    
    glag "参数"
    

    (Note that there is no git in front, because this is not an alias of git, but an alias of shell)

    Recommend oh-my-zsh

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-06-07 09:25:40

    You can define an sh function as an alias, such as

    # https://github.com/jokester/dotted/blob/master/DOTgitconfig#L22
    # 把或HEAD的commit打包成txz
    [alias]
         txz = !"foo () { if [ -n \"\" ]; then treeish=\"\" ; else treeish=HEAD; fi; git archive \"$treeish\" | xz -9 ; } ; foo "

    reply
    0
  • Cancelreply