xargs (or something else) without space before parameter
Asked Answered
P

2

11

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).

Pyuria answered 3/6, 2015 at 9:53 Comment(1)
the whole command is this: git log | grep Author | head | awk '{print $2}' | sed '/[^gismo]/q' | head -n -1 | wc -l | xargs -I% git rebase -i HEAD~%Pyuria
U
16

You can use the -I option of xargs:

git log | blabla | xargs -I% git rebase -i HEAD~%
Undis answered 3/6, 2015 at 10:6 Comment(1)
For more info: gnu.org/software/findutils/manual/html_node/find_html/…Blaubok
S
1

Try this:

git log | blabla | xargs -i bash -c 'git rebase -i HEAD~{}'
Saez answered 3/6, 2015 at 10:6 Comment(1)
the reason of 'bash -c' in this answer is explained here, I think you need it if the first command takes a while to execute: unix.stackexchange.com/questions/65212/…Pyuria

© 2022 - 2024 — McMap. All rights reserved.