0

When under git you modify some files, using git status, comes out the following message:

On branch dev
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   script.php

So I usually used git checkout -- script.php to undo my edits, as suggested.

I found anyway, from a collegue, that git checkout script.php seems to accomplish the same result.

So, my question is: are git checkout -- script.php and git checkout script.php synonyms, or not?

Please, provide at least a link to some documentation that proves what you said. Thanks!

clami219
  • 2,958
  • 1
  • 31
  • 45
  • 1
    See also [What does “--” (double-dash) mean? (also known as “bare double dash”)](http://unix.stackexchange.com/q/11376/8132). –  May 23 '14 at 20:45

1 Answers1

8

If you have tag or branch named script.php, then git checkout script.php will checkout that tag or branch, while git checkout -- script.php will checkout the file in current branch.

Paul
  • 13,042
  • 3
  • 41
  • 59
  • It makes sense... but would you provide some link supporting what you just wrote? In order to accept your answer I want make sure there is nothing else. – clami219 May 23 '14 at 11:06
  • @clami219 Here you go: http://stackoverflow.com/a/1192194/6309 – VonC May 23 '14 at 11:07
  • 3
    @clami219 This is also clearly stated in `git help checkout` man page, example #1. – Paul May 23 '14 at 11:10