有一个项目,我在其中创建了一个foo.py. 对其进行了更改并应用了命令git add foo.py。运行命令git status我看到了这个(让它成为情况 1):
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: foo.py
我没有承诺,即 运行命令git commit并想稍微改进一下解决方案。换句话说,现在我的项目处于这种状态(假设是情况 2):
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: foo.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: foo.py
我现在如何从情况 2 到情况 1?也就是说,从文件中删除更改foo.py,好像在情况 1 之后我没有写任何其他内容。
git checkout foo.py该命令会将指定文件回滚到索引中的状态。
在英文 SO 上找到:https ://stackoverflow.com/questions/3107789/using-git-how-do-you-reset-the-working-tree-local-file-system-state-to-the-st
详细信息可以在官方文档中找到https://git-scm.com/docs/git-checkout
PS甚至输出本身也
git status暗示了这个命令。团队
它会删除所有未跟踪的更改。情况 1 和情况 2 之间的唯一区别是有新的未跟踪更改。此命令将删除它们而不触及跟踪的。(当您在情况 1 中发出 add 命令时,它会被跟踪)。