是否可以使用 reposurgeon 之类的工具将 git 存储库中的 UTF-16 文件的所有提交转换为 UTF-8?

发布于 2024-12-10 08:12:47 字数 221 浏览 0 评论 0原文

我有一个 git 存储库,其中包含 UTF-16 文件。偶然它只是 UTF-16,该文件可以用 7 位 ascii 编码而不会丢失数据。我想使用类似 reposurgeon 将文件转换为 UTF-8 以便git diff 将适用于文件的旧版本,我不必求助于 git difftool。这可能吗?

I have a git repository that has a UTF-16 file in it. Its only UTF-16 by accident, the file could be encoded in 7-bit ascii without a loss of data. I'd like to use something like reposurgeon to convert the file to UTF-8 so that git diff will work with older revisions of the file and I don't have to resort to git difftool. Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

可是我不能没有你 2024-12-17 08:12:47

为什么不将文件转换为 UTF-8 并提交它,例如:

iconv -f UTF-16 -t UTF-8 input-file.txt > input-file.txt.fixed
# Check here that the conversion worked OK
mv -i input-file.txt.fixed input-file.txt
git commit -m 'Convert input-file.txt from UTF-16 to UTF-8' input-file.txt

在澄清注释后更新:

如果您想在 历史记录中的每次提交时重写该文件HEAD,您可以使用git filter-branch,类似于:

git filter-branch --tree-filter \
    'iconv -f UTF-16 -t UTF-8 input-file.txt > input-file.txt.fixed  &&
     mv input-file.txt.fixed input-file.txt' HEAD

当然,如果您以这种方式重写历史记录,如果您与任何人共享此存储库,则可能会导致问题。 (我还没有测试该命令 - 小心使用它,可能只是您存储库的新克隆。)

Why don't you just covert the file to UTF-8 and commit it, e.g. with:

iconv -f UTF-16 -t UTF-8 input-file.txt > input-file.txt.fixed
# Check here that the conversion worked OK
mv -i input-file.txt.fixed input-file.txt
git commit -m 'Convert input-file.txt from UTF-16 to UTF-8' input-file.txt

Update after a clarifying comment:

If you want to rewrite that file at every commit in the history of HEAD, you can use git filter-branch, something like:

git filter-branch --tree-filter \
    'iconv -f UTF-16 -t UTF-8 input-file.txt > input-file.txt.fixed  &&
     mv input-file.txt.fixed input-file.txt' HEAD

Of course, if you're rewriting history in this way, it may cause problems if you have shared this repository with anyone. (I haven't tested that command - use it with care, probably only a new clone of your repository.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文