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).
If you can't use xargs because of whitespace issues, use -exec . Loops are just as inefficient as the -exec parameter since they execute once for each and every file, but have the whitespace issues that xargs have.
xargs is a Unix command which can be used to build and execute commands from standard input.
It converts input from standard input into arguments to a command. Some commands such as grep and awk can take input either as command-line arguments or from the standard input. However, others such as cp and echo can only take input as arguments, which is why xargs is necessary.
pipes connect output of one command to input of another. xargs is used to build commands. so if a command needs argument passed instead of input on stdin you use xargs... the default command is echo (vbe's example). it breaks spaces and newlines and i avoid it for this reason when working with files.
You can use the -I
option of xargs
:
git log | blabla | xargs -I% git rebase -i HEAD~%
Try this:
git log | blabla | xargs -i bash -c 'git rebase -i HEAD~{}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With