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:
stash
, nothing changes. file.txt is still in the working directory.add
the file and then stash
, it goes back to the working directory.reset --hard
, nothing changes. file.txt is still in the working directory.checkout --
the current branch, nothing changes. file.txt is still in the working directory.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?
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.
Comments