search

Home  >  Q&A  >  body text

What is the use of -- in git checkout --<filename>?

A problem on NetEase Cloud Classroom. In fact, there will be no problem using git checkout <filename>. So -- what exactly is it used for? I’ve been searching for a long time but I don’t know which is the correct answer. Please ask someone who knows the answer~

怪我咯怪我咯2834 days ago618

reply all(2)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-02 09:41:05

    is used for escaping. For example, if you have a file named master, if you

    git checkout master

    It will obviously only pull the code of the master branch, which is not consistent with what you want. When you execute

    git checkout -- master

    That’s it to actually pull the master file

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-02 09:41:05

    -- stands for "Anyway, treat the argument after it as a filename (filename)"
    This is a common Unix convention (not git only), such as:

    rm -f      # 不造成任何影响
    rm -- -f   # 删除一个名为 "-f" 的文件

    If the file name you want to operate is preceded by -, you can execute git checkout -- -file-,就可以执行 git checkout -- -file
    如果你要操作的文件名恰好也属于一个分支名,就可以执行 git checkout -- branchIf the file name you want to operate happens to also belong to a branch name, You can execute git checkout -- branch to ensure that the file (named branch) is being operated on.

    reply
    0
  • Cancelreply