Difference between "git checkout <filename>" and "git checkout -​- <filename>" -


http://norbauer.com/notebooks/code/notes/git-revert-reset-a-single-file

i have found post.

but still don't know difference between

  1. git checkout <filename>

  2. git checkout -- <filename>

in situation should use first 1 , second 1 respectively?

the special "option" -- means "treat every argument after point file name, no matter looks like." not git-specific, it's general unix command line convention. use clarify argument file name rather option, e.g.

rm -f      # nothing rm -- -f   # deletes file named "-f" 

git checkout1 takes -- mean subsequent arguments not optional "treeish" parameter specifying commit want.

so in context it's safe use -- always, need when file want revert has name begins -, or same name of branch. examples branch/file disambiguation:

git checkout readme     # discard uncommitted changes                         # _file_ "readme"  git checkout master     # switch working copy                         # _branch_ "master"  git checkout -- master  # discard uncommitted changes _file_ "master" 

and option/file disambiguation:

git checkout -p -- readme  # interactively discard uncommitted changes                            # file "readme"  git checkout -- -p readme  # unconditionally discard uncommitted                            # changes files "-p" , "readme" 

i'm not sure if have branch name begins -. perhaps don't in first place.


1 in mode; "checkout" can several other things well. have never understood why git chose implement "discard uncommitted changes" mode of "checkout" subcommand, rather "revert" other vcses, or "reset" think might make more sense in git's own terms.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -