10

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

Gismo Ranas
  • 6,043
  • 3
  • 27
  • 39
  • 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~% – Gismo Ranas Jun 03 '15 at 10:24

2 Answers2

14

You can use the -I option of xargs:

git log | blabla | xargs -I% git rebase -i HEAD~%
choroba
  • 231,213
  • 25
  • 204
  • 289
1

Try this:

git log | blabla | xargs -i bash -c 'git rebase -i HEAD~{}'
Juan Diego Godoy Robles
  • 14,447
  • 2
  • 38
  • 52
  • 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: http://unix.stackexchange.com/questions/65212/why-doesnt-this-xargs-command-work – Gismo Ranas Jun 04 '15 at 12:37