你如何将git文件恢复到暂存区版本?
假设我有一个名为a.txt
的文件。 我把它添加到暂存区,然后我修改它。 我怎么能把它加回原来的样子呢?
git checkout a.txt
Git告诉你如果你inputgit status
:
# On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: a # # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: a #
git checkout -- a.txt
在这个页面上的其他答案没有--
,并导致一些混淆。
这是Git在inputgit status
时告诉你的:
# On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: a # # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: a #