git-novice
git-novice copied to clipboard
Use -- when calling diff
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
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.
@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 an error that I sometimes get when using Git.
@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.