26

I thought the line

git checkout .

can revert all changes in the current directory and subdirectory for the local working copy. But I also see this popular form:

git checkout -- .

so if -- (the double dash or also called "bare double dash") is to signal the end of command options, then why is it needed in the above case? The . can never be an option so there shouldn't be any confusion.

Community
  • 1
  • 1
nonopolarity
  • 146,324
  • 131
  • 460
  • 740

1 Answers1

20

It's meant to be to resolve ambiguity.

For example, if you had a branch named bob (which would checkout that branch) and a folder named bob (which would revert that folder).

alex
  • 479,566
  • 201
  • 878
  • 984
  • 2
    so you mean `--` is also to signal the end of branch name (and does it signal the end of anything else?). So for `git checkout .` it really doesn't need the `--`? – nonopolarity Apr 22 '14 at 00:23
  • 1
    @動靜能量 for the case of `git checkout .`, there is no ambiguity if there is no branch named `.` (is naming a branch `.` even allowed in git? I'm not sure). Therefore, using `--` in `git checkout -- .` is purely optional. I usually use `--` anyways, out of habit. –  Apr 22 '14 at 00:28
  • 1
    so it looks like in UNIX, `--` is to signal the end of command options. While in `git`, `--` can signal the end of what's first commonly expected. So `git checkout -- main.c` means: I am indicating that there is no branch name explicitly by typing in `--` – nonopolarity Apr 22 '14 at 00:31
  • 1
    I never do `-- .`, it's pointless in that regard (unless of course it's possible and you're silly enough to name a branch `.`). – alex Apr 22 '14 at 00:45
  • 1
    `.` is not a valid branch name in git. You can verify this by typing `git checkout -b .` in any git repository. – Matthew Gatland Oct 10 '17 at 11:13
  • For reverting changes, there is alternate in git v2.23.0. git restore . – rogue lad Aug 28 '19 at 22:36