0

I am beginner wit using git and I wanna know What this git command means

git checkout -- .

I know that git checkout is for switching between branches but I don't know whta the above options means I tried to look on toturials but I didn't options like this one

phd
  • 82,685
  • 13
  • 120
  • 165
Ahmed Mohamed
  • 51
  • 1
  • 9
  • It reverts the files in your working copy to the state of the checked-out revision (without touching untracked files). Basically discards your uncommitted (unstaged) changes. – Thilo Oct 19 '19 at 12:24
  • See https://stackoverflow.com/a/52713/14955 – Thilo Oct 19 '19 at 12:26
  • 2
    Possible duplicate of [dot sign's meaning in git checkout command](https://stackoverflow.com/questions/8275452/dot-signs-meaning-in-git-checkout-command) – phd Oct 19 '19 at 12:32
  • https://stackoverflow.com/search?q=%5Bgit-checkout%5D+%22git+checkout+--+.%22+double+dashes+dot – phd Oct 19 '19 at 12:32
  • https://stackoverflow.com/search?q=%5Bgit-checkout%5D+%22git+checkout+--+.%22 – phd Oct 19 '19 at 12:32
  • Don't feel bad, as `git checkout` is the source of much confusion for both newcomers and seasoned Git users. So much so that Git 2.23 recently split `git checkout` into two subcommands, `switch` and `restore`, each taking on a more focused responsibility than `checkout`. More details at https://www.infoq.com/news/2019/08/git-2-23-switch-restore/ – jub0bs Oct 19 '19 at 13:07
  • The `--` separator in git commands separates file or directory paths from the rest. So, `git checkout -- paths` will only checkout `paths` provided after the the separator. – Serge Oct 19 '19 at 13:25
  • Thanks a lot for your help I understood the meaning of it – Ahmed Mohamed Oct 19 '19 at 16:47

2 Answers2

1

Neither -- nor . are git-specific:

The first -- argument that is not an option-argument should be accepted as a delimiter indicating the end of options. Any following arguments should be treated as operands, even if they begin with the '-' character.

(from https://unix.stackexchange.com/questions/11376/what-does-double-dash-mean-also-known-as-bare-double-dash/11378).

. is the current directory.

git checkout is for switching between branches

If you look at https://git-scm.com/docs/git-checkout, this command has the form

git checkout [<tree-ish>] [--] <pathspec>…​

so it

Overwrite[s] paths in the working tree by replacing with the contents in the index or in the <tree-ish> (most often a commit).

"Paths" are . (the current directory) and "the <tree-ish>" is HEAD (the current commit Git points to), because you didn't specify another.

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
0

It checks out the current directory and subdirectories.

tymtam@x:/mnt/c/tmp/x$ git status

        modified:   x.txt
        modified:   z/z1.txt
        modified:   z/z2/z2_1.txt

tymtam@x:/mnt/c/tmp/x$ cd z                // changing to subdirectory
tymtam@x:/mnt/c/tmp/x/z$ git checkout -- .
tymtam@x:/mnt/c/tmp/x/z$ git status

        modified:   ../x.txt

(I removed git chatter for brevity)

tymtam
  • 31,798
  • 8
  • 86
  • 126