Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的 Git 存储库中有一个包含多个提交的文件,该文件以 16 位 Unicode (UCS-2) 编码,供 Windows 使用。
因此,Git 将其视为二进制文件,而不是文本文件,我看不到不同提交所做的更改。
有没有办法将该文件追溯转换为 UTF-8,即重建历史,就好像该文件一直是 UTF-8 一样,我一直将它作为 UTF-8 文件提交,而不是 16 位 Unicode文件?
要追溯重新编码文件,请使用git filter-branch:
git filter-branch
git filter-branch --tree-filter 'recode utf-16..utf-8 file'
如果您没有recode,请改用更长的时间iconv -f utf-16 -t utf-8 file -o file。如果文件在树的早期版本中不存在,您可能需要追加|| true以便重新编码命令不会失败,并可选择抑制错误输出。
recode
iconv -f utf-16 -t utf-8 file -o file
|| true