Git messed up my files, showing chinese characters in some places

后端 未结 4 920
野的像风
野的像风 2021-02-01 04:44

disclaimer: By Git, I mean \'I\' messed up.

Earlier, I wanted git-gui to show me the diff for which it thinks are binary files.

<
4条回答
  •  醉酒成梦
    2021-02-01 05:22

    To add to a good explaination by @bobince. One solution to this problem (except files with special characters) is to convert everything to utf-8. I solved this by running a python script in notepad++ on all files in a directory (from a computer that did not have the files messed up).

    I found the original script here

    A copy of the notepad++ python script:

    import os;
    import sys;
    filePathSrc="C:\\Temp\\UTF8"
    for root, dirs, files in os.walk(filePathSrc):
        for fn in files:
          if fn[-4:] != '.jar' and fn[-5:] != '.ear' and fn[-4:] != '.gif' and fn[-4:] != '.jpg' and fn[-5:] != '.jpeg' and fn[-4:] != '.xls' and fn[-4:] != '.GIF' and fn[-4:] != '.JPG' and fn[-5:] != '.JPEG' and fn[-4:] != '.XLS' and fn[-4:] != '.PNG' and fn[-4:] != '.png' and fn[-4:] != '.cab' and fn[-4:] != '.CAB' and fn[-4:] != '.ico':
            notepad.open(root + "\\" + fn)
            console.write(root + "\\" + fn + "\r\n")
            notepad.runMenuCommand("Encoding", "Convert to UTF-8 without BOM")
            notepad.save()
            notepad.close()
    

提交回复
热议问题