Git: How to revert 2 files that are stubbornly stuck at “Changed but not committed”?

I spent hours trying to solve a similar issue – a remote branch that I had checked out, which stubbornly showed four files as ‘Changed but not updated’, even when deleting all files and running git checkout -f again (or other variations from this post)!

These four files were necessary, but certainly hadn’t been modified by me. My final solution – persuade Git that they had not been changed. The following works for all checked out files, showing ‘modified’ status – make sure you have already committed/stashed any that have really been modified!:

git ls-files -m | xargs -i git update-index --assume-unchanged "{}"

On Mac OSX, however xargs operates a little bit different (thx Daniel for the comment):

git ls-files -m | xargs -I {} git update-index --assume-unchanged {}

I’ve added this as a placeholder for myself for next time.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)