I picked up a git alias online that is supposed to be the command git rebase -i HEAD~$1
where $1
is a number passed to the alias. Here is the git alias I've got setup in my .zshrc
file:
alias grn="! sh -c \"git rebase -i HEAD~$1\" -"
Example usage from the terminal:
$ grn 3 // This should translate to git rebase -i HEAD~3
The issue i'm running into is that the passed integer argument (eg 3
), is not being passed to my alias so the git alias is effectively always running git rebase -i HEAD~
.
Any clues on how to fix this alias?
Shell alias with parameters is impossible, but git alias is definitely possible. Either
git config alias.grn '! sh -c "git rebase -i HEAD~$1" -'
or
git config alias.grn '!f() { git rebase -i HEAD~$1; }; f'
Run as git grn 3
.
Refering to this question I would say having an alias
which takes parameters is not possible.
You could easily do it with single-line function though.
Just put:
grn() { git rebase -i HEAD~"$1"; }
in .zshrc
and you can run it the same way as an alias.
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.