windows下git亂碼解決方案

來源:互聯網
上載者:User

為了搞定git亂碼問題,幾乎把網上所有git亂碼文章看了一遍,總算讓我解決了。

我用的git和TortoiseGit版本:

msysgit: V1.7.9

http://msysgit.googlecode.com/files/Git-1.7.9-preview20120201.exe

Tortoisegit: V1.7.7.0

http://tortoisegit.googlecode.com/files/TortoiseGit-1.7.7.0-32bit.msi

發現不同的版本解決方案還不一樣,之前試了一個最新版本,發現按網上的方法怎麼弄都不行。後來下了這箇舊的版本,一切OK。

下面是我的設定檔

C:\Documents and Settings\Administrator\.gitconfig
[http]
    sslverify = false
[user]
    name = xxx
    email = xxx@xxx.com
[alias]
    ci = commit -a -s
    co = checkout
    st = status -a
    praise = blame
    am3 = am --signoff --3way --ignore-space-change --keep-cr
[i18n]
    logoutputencoding = gbk
    commitencoding = utf-8
[core]
    editor = emacs
    quotepath = false
    autocrlf = false
[gui]
    encoding = utf-8
[diff]
    external = E:/git-diff-wrapper.sh
[svn]
    pathnameencoding = gbk

 

順便說下,我用的diff是WinMerge,之前用的bc列入黑名單了,不想折騰了,直接用開源的。

E:/git-diff-wrapper.sh

#!/bin/sh

# diff is called by git with 7 parameters:
# path old-file old-hex old-mode new-file new-hex new-mode

#"C:/Program Files/Beyond Compare 3/BCompare.exe" "$2" "$5" | cat
"C:/Program Files/WinMerge/WinMergeU.exe" -e -ub "$2" "$5" | cat

C:\Program Files\Git\etc\git-completion.bash

添加一行

alias ls='ls --show-control-chars --color=auto'

C:\Program Files\Git\etc\gitconfig

[core]
    symlinks = false
    autocrlf = false
[color]
    diff = auto
    status = auto
    branch = auto
    interactive = true
[pack]
    packSizeLimit = 2g
[help]
    format = html
[http]
    sslCAinfo = /bin/curl-ca-bundle.crt
[sendemail]
    smtpserver = /bin/msmtp.exe

[diff "astextplain"]
    textconv = astextplain
[rebase]
    autosquash = true

C:\Program Files\Git\etc\inputrc

set meta-flag on
set input-meta on
set output-meta on
set convert-meta off

C:\Program Files\Git\etc\profile

添加一行

export LESSCHARSET=utf-8

 

我用的editor是windows下的emacs.很好用。但是也存在亂碼問題,在git bash中commit時,如果輸入comment的是中文,可能會顯示不能轉換為utf-8,這可能和編輯器開啟COMMIT_EDITMSG預設編碼有關,並且當COMMIT_EDITMSG中有中文檔案名稱時,emacs的編碼總是c(U),也就是 chinese-gbk-unix。這會導致提交的comment在別處是亂碼。我想了個笨方法,在emacs設定檔中每次負載檔案時,設定使用utf-8編碼:

C:\Documents and Settings\Administrator\.emacs

(defun set_encode_my ()    (set-buffer-file-coding-system  'utf-8))(add-hook 'find-file-hook 'set_encode_my)

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.