首页 > 解决方案 > 有时恢复,有时结帐

问题描述

我开始注意到,有时当我键入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

它开始吓到我了。这里发生了什么?

标签: gitversion-control

解决方案


您几乎可以肯定会在两台不同的计算机上或在运行不同版本的两个不同二进制文件时看到这些消息。git restore 是在 2.23 中引入的,并且在那之后不久就更改了帮助消息(我不记得确切的版本,或者在更改日志中没有提到它,或者我很密集并且找不到它)。

git restore <file>git checkout -- <file>做同样的事情,因此无需担心好奇心之外的差异。git checkout是一个乱七八糟的命令,它做了很多不同的事情——引入git switchgit restore试图让它对初学者更直观,而不改变功能。


推荐阅读