Unstage a deleted file in git

后端 未结 7 1783
我在风中等你
我在风中等你 2020-12-04 04:28

Usually, to discard changes to a file you would do:

git checkout -- 

What if the change I want to discard is deleting the file?

7条回答
  •  余生分开走
    2020-12-04 05:06

    The answers to your two questions are related. I'll start with the second:

    Once you have staged a file (often with git add, though some other commands implicitly stage the changes as well, like git rm) you can back out that change with git reset -- .

    In your case you must have used git rm to remove the file, which is equivalent to simply removing it with rm and then staging that change. If you first unstage it with git reset -- you can then recover it with git checkout -- .

提交回复
热议问题