1

In a local checkout of a git repository I have the following status:

$ git st
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   projects/TouchDetector/5.6.1/_static/doxygen/Doxygen.css

no changes added to commit (use "git add" and/or "git commit -a")

To discard the changes of Doxygen.css I use the command

$ git checkout -- projects/TouchDetector/5.6.1/_static/doxygen/doxygen.css

However, when checking the status I see again the same status:

$ git st
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   projects/TouchDetector/5.6.1/_static/doxygen/Doxygen.css

no changes added to commit (use "git add" and/or "git commit -a")

So is there another, more reliable, way to discard the changes?

I also tried to do

git reset --hard HEAD

and to remove that file, nothing helps.

I would like to fix this issue without the usual solution, i.e. remove and reclone the repository, as it is 3 GB in size.

LeGEC
  • 46,477
  • 5
  • 57
  • 104
Alex
  • 41,580
  • 88
  • 260
  • 469
  • 2
    There could be two files that have the same path and name except the letter cases and have different contents, and your system is not case-sensitive. When the two files are successively checked out, the second overwrites the first. You could check by `git ls-tree -r HEAD | grep -i projects/TouchDetector/5.6.1/_static/doxygen/Doxygen.css`. – ElpieKay Nov 17 '21 at 06:20
  • What is the output of `git diff projects/TouchDetector/5.6.1/_static/doxygen/Doxygen.css` ? – AD7six Nov 17 '21 at 10:02
  • Does this answer your question? [Git refuses to reset/discard files](https://stackoverflow.com/questions/18536863/git-refuses-to-reset-discard-files) – AD7six Nov 17 '21 at 10:03

1 Answers1

1

The behavior that you observe is typical for cases where end-of-line style is different between checked-in and checked-out files. It can also happen when clean and smudge filters are configured. The reason is that timestamps recorded in the index are stale.

Typically, git diff shows nothing in such a situation. Then the obvious fix is to just

git add projects/TouchDetector/5.6.1/_static/doxygen/Doxygen.css

which updates the timestamps in the index, so that git status no longer detects a modification. Do cross-check with git diff --cached that this command did not record any changes.

j6t
  • 9,150
  • 1
  • 15
  • 35