git - 为什么带有路径的 git checkout 不会影响 Pro Git 中声明的索引?
问题描述
我正在研究 Pro Git 以了解如何reset
工作checkout
。我现在了解树,以及每个命令如何根据模式和是否指定路径影响每棵树。但有一件事让我很困惑。
Pro Git 指定使用git checkout
路径时:
[git checkout] 就像 git reset [branch] file 一样,它会在提交时使用该文件更新索引,但它也会覆盖工作目录中的文件。”</p>
但是,在我的实验中,我无法重现这种预期的行为。
如果我在提交的主题分支red
上green
,,,blue
:
9c070df (HEAD -> colors) blue
28a97c1 green
5edafd9 red
使用一个文件,其补丁是:
9c070df (HEAD -> colors) blue
diff --git a/colors.txt b/colors.txt
index 9d8beb6..ff67b54 100644
--- a/colors.txt
+++ b/colors.txt
@@ -1,2 +1,3 @@
red
green
+blue
28a97c1 green
diff --git a/colors.txt b/colors.txt
index a9d1386..9d8beb6 100644
--- a/colors.txt
+++ b/colors.txt
@@ -1 +1,2 @@
red
+green
5edafd9 red
diff --git a/colors.txt b/colors.txt
new file mode 100644
index 0000000..a9d1386
--- /dev/null
+++ b/colors.txt
@@ -0,0 +1 @@
+red
如果HEAD
是蓝色的,我git reset 5edafd9 -- colors.txt
,我会有
+ green
+ blue
在工作树上,和
- green
- blue
在索引中,这是预期的,因为唯一的行red
应用于索引。因此,当工作树与索引进行比较时,看起来像是添加了这些行,而当索引与头部进行了比较时,看起来这些行被删除了。这是预期和理解的。
但是当 I 时git checkout -- colors.txt
,只有工作树受到影响,索引完好无损。
为什么是这样?
解决方案
推荐阅读
- python - python从csv返回特定时间在特定服务器下使用的许可证的次数
- reactjs - 在同一个 React 本机应用程序中使用 LocalNotificationSchedule 和 Firebase 通知
- asp.net-mvc - ASP.NET MVC 5 中的下拉填充错误
- css - 在具有多个单元的 css-calc 中嵌套多个事物
- node.js - 如何在节点 js 应用程序中使用本地主机上的通配符子域
- javascript - 打字稿动态和安全地将元素添加到数组
- linux - 部署到 Linux 应用服务时 Angular CLI 应用未运行
- python - 在 Scrapy 和 Selenium 之间共享网络会话
- c# - 我可以替换等待方法吗?调用异步任务返回?
- gcloud - 没有消息时的 Google Cloud PubSub 费用