Unstage a deleted file in git

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

    I tried the above solutions and I was still having difficulties. I had other files staged with two files that were deleted accidentally.

    To undo the two deleted files I had to unstage all of the files:

    git reset HEAD .
    

    At that point I was able to do the checkout of the deleted items:

    git checkout -- WorkingFolder/FileName.ext
    

    Finally I was able to restage the rest of the files and continue with my commit.

提交回复
热议问题