Gismo Ranas
Gismo Ranas

Reputation: 6442

xargs (or something else) without space before parameter

I would like to execute something like this (git squash):

git rebase -i HEAD~3

extracting the 3 from git log:

git log | blabla | xargs git rebase -i HEAD~

This does not work because xargs inserts a space after HEAD~.

The problem is that I want to alias this command, so I cannot just use

git rebase -i HEAD~`git log | blabla`

because the number would be evaluated just when I define the alias.

I don't have to use xargs, I just need an alias (preferably not a function).

Upvotes: 11

Views: 4176

Answers (2)

choroba
choroba

Reputation: 242103

You can use the -I option of xargs:

git log | blabla | xargs -I% git rebase -i HEAD~%

Upvotes: 16

Juan Diego Godoy Robles
Juan Diego Godoy Robles

Reputation: 14965

Try this:

git log | blabla | xargs -i bash -c 'git rebase -i HEAD~{}'

Upvotes: 1

Related Questions