Git: Alias error: Use '--' to separate paths from revisions

Jacob Krieg picture Jacob Krieg · Jun 12, 2013 · Viewed 8.7k times · Source

I created a git command that shows me the diff between the HEAD and the last Git-SVN commit.

Git is the command

git diff `git log --grep git-svn-id | grep commit | sed "s/commit //g" | head -1` HEAD

And I wanted to make an alias for it and I did it like this:

git config --global alias.diffsvn 'diff `git log --grep git-svn-id | grep commit | sed "s/commit //g" | head -1` HEAD'

but when I run git diffsvn and have the output of that command but I get

fatal: ambiguous argument '`git': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git [...] -- [...]'

How can I make this alias work?

Answer

cforbish picture cforbish · Jun 12, 2013

Short answer is you need to add a !git, in front of the diff, to tell git it is a shell command. So this:

git config --global alias.diffsvn '!git diff `git log --grep git-svn-id | grep commit | sed "s/commit //g" | head -1` HEAD'

I suggest this instead:

git config --global alias.diffsvn '!git diff `git log --grep git-svn-id -1 | sed -n "s/commit //p"` HEAD'