Blog 1

Random Talk on Random Thoughts

Double Hyphens in Git Diff

| Comments |

Two months ago, I wrote my first list of Git commands, and said that I didn’t know how to use Git commands to view the changes.1

Now, I can understand how one can “use ‘--’ to separate paths from revisions [or branches]”.

For example, if a developer relies on this Git cheatsheet for blogging with Octopress, then he/she will learn some Git commands, for example:

  1. git diff <branch> to view the uncommitted changes;
  2. git diff <path> to show the uncommitted changes in files under <path>.

Those commands should be enough for most cases. However, if he/she blogs with Octopress, then he/she will encounter the some problems:

  1. git diff source can’t view the uncommitted changes on source branch; (Click the linked post in footnote 1 for the error thrown by Git.)
  2. git diff source can’t show the uncommitted changes in files under source folder.

In order to use git diff to do the intended task, one has to avoid ambiguity.

  1. If necessary, one can use -- to separate branch name(s) from file/path names;
  2. One can use ./source to mean source folder.
$ git diff origin/source source
fatal: ambiguous argument 'source': both revision and filename
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
$ git diff origin/source source --  # correct command
$ git diff ./source                 # correct command

If one doesn’t want to type in shell commands, one may consider using fugitive.vim: in a window invoked by :Gst, press D at the line where the modified file is shown.


  1. Tam, V. 2014, Jun 16. My Git Command List (1). Retrieved from https://vincenttam.github.io/blog/2014/06/16/my-git-command-list-1/#comparing-branches 

Comments