Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In "git checkout -- files", what does "--" mean?

Tags:

git

Is it the "end of option" I am used to see in bash (and if yes, why do we use it) or is it a Git notation for the Index or the HEAD?

like image 883
e-satis Avatar asked Mar 27 '10 22:03

e-satis


People also ask

What does git checkout on a file do?

The git checkout command lets you navigate between the branches created by git branch . Checking out a branch updates the files in the working directory to match the version stored in that branch, and it tells Git to record all new commits on that branch.

What does GitHub checkout mean?

Checkout is the command used to switch between the different branches of a GitHub repository. When a branch is checked out, all files in the working directory are updated to match the versions stored in that branch.

Does git checkout change files?

The git checkout command can be used in a commit, or file level scope. A file level checkout will change the file's contents to those of the specific commit.

Why is it called Checkout git?

DESCRIPTION Updates files in the working tree to match the version in the index or the specified tree. If no paths are given, git checkout will also update HEAD to set the specified branch as the current branch. checkout (co): Check out a working copy from a repository.


1 Answers

The -- separates the paths from the other options. From the documentation:

git checkout [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <paths>...  

If this notation didn't exist the following two commands would be ambiguous:

git checkout <tree-ish> <path1> <path2> git checkout <path1> <path2> <path3> 

With the -- notation it is clear which is meant:

git checkout <tree-ish> -- <path1> <path2> git checkout -- <path1> <path2> <path3> 

The documentation I linked to above includes an example of when you might need it:

$ git checkout hello.c

If you have an unfortunate branch that is named hello.c, this step would be confused as an instruction to switch to that branch. You should instead write:

$ git checkout -- hello.c

like image 180
Mark Byers Avatar answered Oct 07 '22 20:10

Mark Byers