Cannot remove file from working directory

Ilya Kogan

I'm trying to checkout a branch, but keep getting this error:

error: Your local changes to the following files would be overwritten by checkout:
        file.txt
Please, commit your changes or stash them before you can switch branches.
Aborting

However:

  • When I stash, nothing changes. file.txt is still in the working directory.
  • When I add the file and then stash, it goes back to the working directory.
  • When I reset --hard, nothing changes. file.txt is still in the working directory.
  • When I checkout -- the current branch, nothing changes. file.txt is still in the working directory.
  • I even tried git rm -f file.txt and then stash. Doesn't help either.

And after doing all this, I'm still unable to checkout a different branch because I'm stuck with file.txt.

How can I explain what's happening here? And how do I get rid of file.txt?

I'm working with git-scm on Windows, if it matters.

EDIT: git diff --check shows that there's a difference in trailing whitespace. Why can't git just treat trailing whitespace just like any other text difference, and instead acts so strangely by not letting me reset or stash? Is this behavior configurable?

Ilya Kogan

We ended up removing the text=auto setting, because we all work on Windows anyway. Now Windows line-endings are kept in the repository and it seems to have solved the issue.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related