Git refuses to reset/discard files Git refuses to reset/discard files git git

Git refuses to reset/discard files


Normalize line endings

The change that is in the modification is deleting all lines and adding them again.

This is because the newlines are being changed between the committed files and the files on disk.

Github has a handy page detailing how to deal with this kind of problem, in brief (for linux/OSX), step one is to change your git config so it sorts out the line endings for you:

git config --global core.autocrlf input

Then commit line-endings normalization:

git rm --cached -r .# Remove everything from the index.git reset --hard# Write both the index and working directory from git's database.git add .# Prepare to make a commit by staging all the files that will get normalized.# This is your chance to inspect which files were never normalized. You should# get lots of messages like: "warning: CRLF will be replaced by LF in file."git commit -m "Normalize line endings"# Commit

And then, line endings should be handled correctly. See the help page on github for more information, or the relevant section of the git docs formatting and whitespace.

Resolving linux-machine conflicts

the staging server is locked because it won't pull new edits.

The error message reads "Your local changes to the following files would be overwritten by merge:", that means they contain local changes which should either be committed or discarded before continuing. Assuming normal usage for the staging server (it doesn't have any intentional changes) the local changes can be discarded. For example do the following:

$ git fetch origin# Retrieve updates$ git reset --hard origin/master# Forcibly change the current branch to match origin/master

This will retrieve the repository history, without updating the working copy, and then update to exactly match the master branch in the repository. Note that the last command will discard all uncommitted changes.


I always mentioned making sure that your core.autocrlf is set to false, as in "Git : stuck repo using stash after crlf normalization?"

git config --global core.autocrlf false

Also make sure that you don't have a .gitattributes file with eol directives that would try to convert the end-of-lines.
The basic idea is: do you still see that error message when you make sure there is no automatic conversion of any sort?


But just in case, consider also "Git rebase fails, 'Your local changes to the following files would be overwritten by merge'. No local changes?"

I'm on a mac, and this obscure config change seemed to fix all my woes regarding unstaged changes when there were none.

git config --global core.trustctime false


I just spent 2 hours (!) on the same issue with a .svg file (Scalar Vector Graphics), which kept changing after 'revert' without my intervention.

So the file shows up as modified in 'git status'; reverting it succeeds, but it keeps changing, so the 'pull' is failing again and again.... so annoying!

No luck with 'git reset', 'git ignore', 'git untrack' etc...

Finally, I solved it by removing the file from my local system (not 'git delete', just Shift + Delete) >> now 'pull' request passes, and the file is fetched from the remote repository.

So easy, I could cry!