git - `git checkout -- foo.txt` 和 `git checkout foo.txt` 的区别
问题描述
通常我git checkout -- foo.txt
用来重置工作树中的特定文件。今天我不小心使用了git checkout foo.txt
(没有--
),它似乎做了同样的事情。
$ git checkout -- foo.txt # no output
$ git checkout foo.txt
Updated 1 path from the index
所以我想知道,这两者有什么区别?或者,有吗?
解决方案
简单的回答:
# 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 找不到分支,那么它会寻找一个文件并签出这个文件。
看看官方的 Git doku 关于git checkout
推荐阅读
- java - NewObject 上的 Java JNI 崩溃。其他电话正在工作。
- javascript - Express / Nodejs 路由无法获取对象中的键
- vbscript - 如何使循环 VBScript 静默运行?
- google-chrome - Chrome v70+ 在 td 单元格中存在 innerText 问题
- angular - Angular 6 - 如何在单元测试中模拟 router.events url 响应
- sql - Ms Access SQL 中的多个右连接问题,返回 SYNTAX ERROR
- java - 从集合中读取时为什么不使用超级通配符
- java - 打开文档时如何选择单选按钮组的一个单选按钮?PDFBox 2.0.11
- bitbucket - 尝试登录 bitbucket 时获取“unencrypted_secret”
- javascript - 使用 dom 弹跳图像