Search code examples
gitgit-checkoutgit-reset

Can't reset a file to a specific commit using Git


I have a modified file which I want to rever to whatever is in the latest commit but it's "stuck" there always being marked as modified.

$ git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   index.php
#
no changes added to commit (use "git add" and/or "git commit -a")

I then try:

$git checkout -- index.php

But the output of git status is still the same. I then try:

$git reset --hard master
HEAD is now at 02c9613 test commit message

And the output of git status is STILL the same.

Any ideas on how I can get rid of the supposed changes on that file?


Solution

  • You might be running into a whitespace issue try git config --global apply.whitespace nowarn for that.

    If that doesn't work, I'd say you've run into a bug. Save the local clone for future reference (I hope it's not too big) and create a bug report. Especially the facts that:

    • you haven't modified the file yourself
    • other files don't show this problem

    are signs that it might just not be you that made the mistake here. Whether you can reproduce the problem on a clean repo would be interesting information too.