代码之家  ›  专栏  ›  技术社区  ›  rocksNwaves

有时恢复,有时签出

  •  0
  • rocksNwaves  · 技术社区  · 4 年前

    我开始注意到有时候我打字的时候 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
    

    我开始害怕了。这是怎么回事?

    0 回复  |  直到 4 年前
        1
  •  6
  •   Soren Bjornstad Alex Martelli    4 年前

    几乎可以肯定,在两台不同的计算机上,或者在不同的版本上运行两个不同的二进制文件时,都会看到这些消息。 git restore was introduced in 2.23 ,并且帮助消息在那之后不久就发生了变化(我不记得具体是哪个版本,或者在 changelogs 或者我太密集了找不到它)。

    git restore <file> git checkout -- <file> 做同样的事情,这样就不必担心除了好奇心之外的差异。 git checkout 是一个混乱的命令,它执行大量不同的任务 git switch git还原 是为了让初学者更直观,而不改变功能。