Convert git repository file encoding

后端 未结 1 954
我寻月下人不归
我寻月下人不归 2020-12-05 02:35

I have a large CVS repository containing files in ISO-8859-1 and want to convert this to git.

Sure I can configure git to use ISO-8859-1 fo

相关标签:
1条回答
  • 2020-12-05 03:21

    You can do this with git filter-branch. The idea is that you have to change the encoding of the files in every commit, rewriting each commit as you go.

    First, write a script that changes the encoding of every file in the repository. It could look like this:

    #!/bin/sh
    
    find . -type f -print | while read f; do
            mv -i "$f" "$f.recode.$$"
            iconv -f iso-8859-1 -t utf-8 < "$f.recode.$$" > "$f"
            rm -f "$f.recode.$$"
    done
    

    Then use git filter-branch to run this script over and over again, once per commit:

    git filter-branch --tree-filter /tmp/recode-all-files HEAD
    

    where /tmp/recode-all-files is the above script.

    Right after the repository is freshly upgraded from CVS, you probably have just one branch in git with a linear history back to the beginning. If you have several branches, you may need to enhance the git filter-branch command to edit all the commits.

    0 讨论(0)
提交回复
热议问题