Unstage a deleted file in git

后端 未结 7 1761
我在风中等你
我在风中等你 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:12

    If it has been staged and committed, then the following will reset the file:

    git reset COMMIT_HASH file_path
    git checkout COMMIT_HASH file_path
    git add file_path
    

    This will work for a deletion that occurred several commits previous.

提交回复
热议问题