Search code examples
gitdelete-filegit-stage

Unable to unstage a deleted file with git


After I checked out a branch and did a "git pull" on it, git thinks that I have deleted a file:

> git status
On branch feature-support
Your branch is up to date with 'origin/feature-support'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        deleted:    mvnw

However, that is not true, as the mvnw file is still in the directory. I have tried the following commands from this answer and other answers and I am not able to unstage this deleted file, which is preventing me from unstashing some files:

git restore --staged mvnw
git reset -- mvnw
git checkout -- mvnw
git reset HEAD mvnw
git reset HEAD .
git reset HEAD
git restore --staged -- mvnw
git reset mvnw
git checkout mvnw
git checkout .
git reset --hard
git clean -fd
git clean -f

How can I unstage that deleted file?

EDIT: Running the git restore --staged . command resolved the issue for the mvnw file, however, a new deleted file showed up in Changes to be committed and I can't get it to go away:

deleted: our-project/src/test/resources/etc/ABCD-EFGH.

Solution

  • For the mvnw file, I resolved the issue with the git restore --staged . command.

    For the our-project/src/test/resources/etc/ABCD-EFGH. file, I resolved the issue with the git config core.protectNTFS false command. Viewing the our-project/src/test/resources/etc/ directory on GitHub, I can see 3 files:

    ABCD-EFGH
    ABCD-EFGH.
    ABCD-EFGH.pdf
    

    It appears Windows cannot handle a file named ABCD-EFGH. (with a dot at the end), and the git config core.protectNTFS false command resolves that. I still see deleted: our-project/src/test/resources/etc/ABCD-EFGH. in the Changes not staged for commit section, but it is not preventing any git operations like it did when it was listed under the Changes to be committed section.