Git cannot undo modified files

If you want to just change a file back to the way it was after the last commit, just do a git checkout [file] to get a particular file. But a git reset --hard should have done that to the whole tree. If you think it's just the line-endings, do a git diff and then a git diff --ignore-all-space. If the first diff shows changes and the second one doesn't, then at least you know you have a line-ending problem, in which case you might want to look at this description of git and line endings.


Contributing my case: There was a file that had a modified state and I could not reset this file using git reset --hard. None of the above commands helped me, the file just was always in modified state.
What was more interesting is that this issue persisted even after the new clone! But git gave me a hint:

... bla bla bla git clone ....
Resolving deltas: 100% (37818/37818), done.
warning: the following paths have collided (e.g. case-sensitive paths
on a case-insensitive filesystem) and only one from the same
colliding group is in the working tree:

  'a/b/c/Myfile.kt'
  'a/b/c/MyFile.kt'

It's turned out that someone on a case-sensitive file system (linux) had accidentally committed two files with the same name, but in different cases and different content. And when I opened this repo on a case-insensetive file system (macOs, windows), git thought that this is the same file and always showed me it as "modified" from MyFile.kt to Myfile.kt or from Myfile.kt to MyFile.kt.

So, I just removed an irrelevant file and leaved only one.


Try the approach explained in the "Re-normalizing a repo" section of this github article after making sure your EOL settings have sensible values (for your OS and repo policy)