git checkout-foo.txt和git checkout foo.txt之间的区别 [英] Difference between `git checkout -- foo.txt` and `git checkout foo.txt`

查看:67
本文介绍了git checkout-foo.txt和git checkout foo.txt之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常我使用 git checkout-foo.txt 重置工作树中的特定文件.今天,我不小心使用了 git checkout foo.txt (没有-),而且看起来也一样.

Normally I use git checkout -- foo.txt to reset a specific file in my worktree. Today I accidentally used git checkout foo.txt (without --) and it seems it did the same.

$ git checkout -- foo.txt  # no output
$ git checkout foo.txt
Updated 1 path from the index

所以我想知道,两者之间有什么区别?或者,有吗?

So I am wondering, what is the difference between the two? Or, is there any?

推荐答案

简单答案:

# checkout the branch foo.txt if this branch exist, otherwise the file
$ git checkout foo.txt

# checkout the file foo.txt
$ git checkout -- foo.txt

因此,如果您需要-,则用于文件,而没有两个字符,则表示分支.如果Git找不到分支,则它将查找文件并检出该文件.

So if you need -- it is for files, without the two characters, it is meaning for branches. If Git can't find a branch, then it will look for a file and checkout this file.

查看有关 git结帐的官方Git doku

Look at official Git doku about git checkout

这篇关于git checkout-foo.txt和git checkout foo.txt之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆