SmartGit — How to fix an Index which contains the same file name multiple times

How to fix an Index which contains the same file name multiple times, but with different encodings

Источник: SmartGit - Git/Mercurial/SVN Client: How-Tos.

Проблема появилась после перехода на msysgit 1.7.10 - файлы с русскими именами перестали правильно отображаться, правильно храниться в индексе и правильно восстанавливаться. После перехода между windows и linux всё становится совсем плохо. Предлагаемое решение - удалить их, что само по себе не очено просто, так как имена крайне странные.


If an encoding problem in the Index is encountered, SmartGit/Hg will show an error message which contains information about the problematic file. The resolution is performed using Git from the command line:

  • cd to your repository.
  • Invoke git status to be sure you have a clean working tree and Index. If not clean, either commit or stash away your local modifications.
  • For msysgit, on Windows: invoke bash.exe to enter Git's shell.
  • Invoke git ls-files | grep <readable-part-of-the-file-name>.
  • Inspect the output of the command and identify the offending entries: usually they will be almost identical, but only differ at certain positions where the octal encoding (\xyz) slightly varies. In the next step we will remove these offending entries from the repository (and re-add them again, if necessary). Hence, for every offending entry <path-to-file>:
  • Make a backup of <path-to-file> and
  • Invoke git rm --cached "`printf "<path-to-file>"`" (Note: all the quotes are necessary!). Например, можно написать
    git rm --cached "`printf "*.bat"`"


On Windows, you may also work without bash.exe: just open a command line (DOS box) and invoke git rm --cached <path-to-file-pattern> with <path-to-file-pattern> being an unambiguous pattern of the file's path where the non-ASCII characters are replaced by ?. E.g.: x?y.txt.

  • After all entries have been removed, invoke git commit -m "clean up bad encoding of file names".
  • If necessary, re-add the entries (this time with correct encoding) with git add . and finally commit with git commit --amend -m "clean up bad encoding of file names".


Leave a Reply