Monday, April 13, 2015

Git shows modified files but no local changes have been made

Problem:

I checked out updated my master branch to work on some hot fixes, but one I had pulled in the latest master branch, I found two files which were being tracked as modified. I didn't have any local changes to these files before. Where did these come from?





Solution:
For me this was due to git not handling case sensitive changes. Another developer had changed an upper case letter to lower case for a file name. Here is how I solved the problem.

Rename the directory in question to something else. Git should now show the files as deleted. Specifically `git rm` the directory with the old name and casing (you may need to force it) and run `git status` to be sure that only the now incorrect casing directory is staged for commit. Now commit your changes.





Manually rename the directory back to the expected format (the newest format) of it's title. Run `git status` again. If you still see one or more of those files as modified, checkout the latest version of the file. Note: If the directory is no longer around, manually create it with the correct casing and then checkout the files it has from your repo.



Now check your project state. You should have a clean state with 1 commit ahead of master.



No comments: