本文翻译自:Unstage a deleted file in git
Usually, to discard changes to a file you would do: 通常,要放弃对文件的更改,您将执行以下操作:
git checkout -- <file>
What if the change I want to discard is deleting the file? 如果我要丢弃的更改是删除文件怎么办? The above line would give an error: 以上行会出错:
error: pathspec '<file>' did not match any file(s) known to git.
What command will restore that single file without undoing other changes? 什么命令将恢复该单个文件而不撤消其他更改?
bonus point: Also, what if the change I want to discard is adding a file? 奖励点:另外,如果我要丢弃的更改是添加文件怎么办? I would like to know how to unstage that change as well. 我想知道如何取消这种变化。
<