git - 有时恢复,有时结帐
问题描述
我开始注意到,有时当我键入git status
检查分支时,我会看到以下文本:
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: some_code_or_file.py
有时我会看到:
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: some_code_or_file.py
它开始吓到我了。这里发生了什么?
解决方案
您几乎可以肯定会在两台不同的计算机上或在运行不同版本的两个不同二进制文件时看到这些消息。git restore
是在 2.23 中引入的,并且在那之后不久就更改了帮助消息(我不记得确切的版本,或者在更改日志中没有提到它,或者我很密集并且找不到它)。
git restore <file>
并git checkout -- <file>
做同样的事情,因此无需担心好奇心之外的差异。git checkout
是一个乱七八糟的命令,它做了很多不同的事情——引入git switch
并git restore
试图让它对初学者更直观,而不改变功能。
推荐阅读
- java - 当我尝试解析字符串时,我的应用程序崩溃了
- java - Retrofit 2 通过MS graph api发送邮件返回参数'Message'的值为空
- service - 无法启动 systemd 服务
- angular - 如何在引导程序 4 中显示选定的选项?
- javascript - 如何从已完成的 Javascript 事件中触发 CSS 的更改?
- java - 连接到 AWS DocumentDB 时出现 com.mongodb.CommandFailureException
- laravel-5 - Laravel 在数据库查询中合并计数
- python - dockerfile 安装 mysql 并在 ubuntu 镜像中运行脚本
- javascript - 在为 gRPC 流在服务器端调用 .end() 之前,如何在客户端接收数据
- c# - c# WPF 如何在加载 xaml 窗口时显示我的进度条?