Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
474 views
in Technique[技术] by (71.8m points)

git config - Pass an argument to a Git alias command

Can I pass arguments to the alias of a Git command?

I have some alias in Git config, like so:

rb1 = rebase -i HEAD~1
rb2 = rebase -i HEAD~2
rb3 = rebase -i HEAD~3
rb4 = rebase -i HEAD~4
....

Is it possible to make an rb alias so that git rb <x> works for any <x>?

I tried this alias:

rb = rebase -i HEAD~

but then for instance git rb 8 does not work.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you consider the Git Faq section "Git Aliases with argument", you could do it, but by calling git through a shell:

[alias]
        rb = "!sh -c "git rebase -i HEAD~$1" -"

I haven't tested it yet, but if you can pass an argument, that would be the way to do it.

A similar solution would be to use a shell function:

[alias]
        rb = "!f() { git rebase -i HEAD~$1; }; f"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

62 comments

56.6k users

...