git-novice icon indicating copy to clipboard operation
git-novice copied to clipboard

Use -- when calling diff

Open rgaiacs opened this issue 7 years ago • 4 comments

Sometimes when I use git diff I receive

fatal: ambiguous argument 'foo': unknown revision or path not in the working tree.

as an error message. This kind of message could be avoided by using -- to separate commits and files.

What about use -- in the lesson as a good practice? So instead of

$ git diff HEAD mars.txt

we will use

$ git diff HEAD -- mars.txt

rgaiacs avatar May 11 '18 14:05 rgaiacs

git diff is first introduced in lesson 04, without any arguments, and is used only to compare changes with HEAD, which is the default behaviour. In that lesson, I wouldn't add anything else.

diff is used for the first time with a file as an argument in lesson 05. However, the way is used here is git diff HEAD mars.txt. Do you know if this syntax (with HEAD) can lead to the same ambiguity you report? If that is not the case, I think it's already safe enough. There is a sentence, however, that says

which is the same as what you would get if you leave out HEAD (try it)

in light of your comment, we could change that and briefly mention what -- is for.

martinosorb avatar Dec 14 '18 15:12 martinosorb

@rgaiacs, is this an error you receive when going through the content of the lesson, or an error that you sometimes get when using git? I have not encountered this error in the lesson before.

kekoziar avatar Feb 22 '19 20:02 kekoziar

@kekoziar an error that I sometimes get when using Git.

rgaiacs avatar Feb 23 '19 10:02 rgaiacs

@kekoziar @rgaiacs I saw this error when I was preparing for my instructor training. In my case, it was because I was in the git repository, but I was not actually in the directory with my file and did not supply the path to the file. Once I used cd to move into the proper subdirectory, I no longer saw this error. Your case may be different, but see if that applies next time you see it.

quist00 avatar Mar 22 '19 00:03 quist00