星期二, 2月 05, 2013

Git for Windows中文檔名不再亂碼

昨天看到 Getting Started with Git in Visual Studio and Team Foundation Service,也就是說微軟官方將正式支援Git做為Source Control Provider。目前需要安裝Visual Studio 2012 Update 2 CTP 2Visual Studio Tools for Git。所以我也趁機丟掉Subversion,全面投到Git的懷抱。



其實在Git v1.7.10之後,就修改Windows版本儲存時會用UTF-8處理檔名,只是要做些設定,詳情請參考Git for Windows Unicode Support。它和中國高手做的patch是一樣的,在所有平台都會使用UTF-8處理檔名! 從此在各平台都可順利開發共用repository。我個人是不喜歡Git去改我的line ending,詳情看Dealing with line endings

以下節錄Github的說明:

Windows settings

Console font (per user)

The default console font does not support Unicode. Change the console font to a TrueType font such as Lucida Console or Consolas. The setup program can do this automatically, but only for the installing user.

Git settings

These can be set per user (with the --global option) or per repository, the repository settings take precedence.

Disable quoted file names

By default, git will print non-ASCII file names in quoted octal notation, i.e. "\nnn\nnn...". This can be disabled with
 git config [--global] core.quotepath off

Disable commit message transcoding

Previous Git for Windows required to set the i18n.logoutputencoding to your Windows system's default OEM encoding for proper console output of non-ASCII commit messages. This is no longer necessary. Remove this or set it to 'utf-8':
 git config [--global] --unset i18n.logoutputencoding
The i18n.commitencoding setting should also be removed or set to 'utf-8' to support commit messages on the command line (git commit -m "..." from cmd.exe, MSYS bash won't let you enter non-ASCII characters):
 git config [--global] --unset i18n.commitencoding

Disable SVN file name transcoding

If you're using git-svn, reencoding SVN file names is no longer necessary (SVN also stores file names in UTF-8):
 git config [--global] --unset svn.pathnameencoding

Migrating old Git for Windows repositories

This is only relevant if you used non-ASCII file names with non-Unicode Git for Windows versions.
Previous Git for Windows versions stored file names in the default encoding of the originating Windows system, making these repositories incompatible with other Windows language-versions and other Git versions (including Cygwin-Git and JGit / EGit on Windows).
The Unicode-enabled Git for Windows stores file names UTF-8 encoded.

Checking if a repository contains non-ASCII file names

The recodetree check command scans the entire history of a git repository and prints all non-ASCII file names. If the output is empty, no migration is necessary.
Note: the recodetree script doesn't work with quoted characters, disable quoted file names first: git config [--global] core.quotepath off

沒有留言: