I was able to pull changes from origin/master
into master
while working in another branch by using this command:
git fetch origin master:master
For a deeper dive into what's going on, check out the excellent answer to this Stack Overflow question. The main take-away for me was that this command only works for a fast-forward merge.
Here is the source of the error message:
$ git log %ad
fatal: ambiguous argument '%ad': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
You will get the same error message from the following two commands:
$ git log --pretty=format:%h %ad | %s%d [%an] --graph --date=short
$ git log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
The problem is that git log
receives the following two arguments: --pretty=format:%h
(or --pretty=format:\"%h
) and %ad
. The rest, at least when executed directly as a command in bash, is a pipe to the command %s%d
, which usually does not exists. The full error message on my system thus looks like this:
$ git log --pretty=format:%h %ad | %s%d [%an] --graph --date=short
bash: %s%d: command not found
fatal: ambiguous argument '%ad': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
All this demonstrates that the quoting somehow got lost and %ad
is interpreted as a parameter for git log. To prevent that you have to find the correct combination of quoting and escaping so that the format string is quoted correctly at time of execution.
The git config manual about alias and quoting:
Arguments are split by spaces, the
usual shell quoting and escaping is
supported. quote pair and a backslash
can be used to quote them.
From this line I was not able to figure out how quoting and escaping works. I tried some combination of quoting and escaping in the alias but was not able to make any sense out of it.
The following lines you posted in your question works fine on my system:
[alias]
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
You will have to experiment to get the right combination on you system while using PuTTY and all.
Best Answer
If you're going to use positional parameters in git aliases, be sure to specify
sh -c
. The following worked for me locally:(dead link)
The "why" relates to the way git parses the alias commands and is summed up in this gmane thread.The
-
at the end of the command signalssh
that option processing is finished. Fromman sh
:If it weren't present, it would introduce a bug in the alias, by treating
$1
as an option on thesh
command instead of as a positional argument. Consider this trivial example:In the first case, 'foo' was consumed by
sh
as an option. In the second, it's correctly interpreted as$1
on the string.