Search code examples
gitgit-checkoutgit-reset

Why couldn't I discard a file from my working directory in Git?


I have a modified file in a Git working directory which I want to discard. This file is not in a submodule.

I tried 3 different commands and nothing helped.

  1. git checkout -- <file>, or git checkout <file>

  2. git reset HEAD --hard

  3. git stash save --keep-index

How to discard that file?

Screenshots:

enter image description here enter image description here


Solution

  • As long as you set git config --global core.autocrlf true, you will see changes applied automatically to those file.

    I would recommend: