views:

494

answers:

2

Can I embed the following bash shell code:

for name in $(git diff --name-only $1); do git difftool $1 $name & done

directly into the creation of a git alias:

git config --global alias.diffall ***my-bash-code-here***

This leads on from my previous question/answer on SO, where I put the code into a .sh file and then aliased to the file:

git config --global alias.diffall '!sh diffall.sh'

But in the never-ending quest for simplicity, there's gotta be a way to skip the file and insert code directly into the alias? I can't figure out the format...

+3  A: 

Adding these 2 line to your .git/config file should do the trick.

[alias]
    diffall = '!for name in $(git diff --name-only $1); do git difftool $1 $name & done'

Edit: presumably the git-config version works too, but I like to keep my aliases in the config file for ease of management.

There is a nice page on the git wiki that explains aliases very clearly: http://git.or.cz/gitwiki/Aliases In particular, read 'advanced aliases with arguments'

David Claridge
git config --global will store your aliases on $HOME/.gitconfig, where (IMO) they are even easier to manage; almost no aliases need to be repository specific. (Repo specific go into repo/.git/config)
kaizer.se
Thanks David, but it just won't work for me - that or any of the variations in the great link you included. Maybe I should have mentioned that I'm running in Windows environment?Thanks Kaizer, agreed, this is 'global' for me.
Seba Illingworth
+6  A: 
git config --global alias.diffall '!sh diffall.sh'

This is redundant in one way. If you are going to add 'diffall.sh' into your $PATH anyway, why not save it as 'git-diffall', and save yourself from declaring an alias. Yes, "git diffall" will run it.

kaizer.se
Hah, well there ya go, simple as that :) Thanks kaizer !
Seba Illingworth