What is the use of -- in git checkout --<filename>?
怪我咯
怪我咯 2017-05-02 09:39:05
0
2
626

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~

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
曾经蜡笔没有小新

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

phpcn_u1582

-- 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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template