2011-06-11

[git] git cherry-pick 時保有中文訊息

今天在實驗 cherry-pick 時
不意外的發現每個中文訊息都變成亂碼

又在一次的亂槍打鳥隨機搜尋時
發現msysgit 的設定是由 /etc/profile 所控制
然後在檔案最底下發現了這一段代碼
# read user-specific settings, possibly overriding anything above
if [ -e ~/.bashrc ]; then
    . ~/.bashrc
elif [ -e ~/.bash_profile ]; then
    . ~/.bash_profile
elif [ -e /etc/bash_profile ]; then
    . /etc/bash_profile
fi
由以上代碼可知 如果再 windows 使用者資料夾下增加 .bash_profile 這個檔案的話就會被包含進去 msysgit 的環境設定內

 於是我建立了檔案並且內容為
# utf-8 確認可在 cherry-pick 時保有中文訊息
export LESSCHARSET=utf-8
接著又再一次的使用 git cherry-pick 指令
這次就成功的保有中文而沒有變成亂碼了

補充說明以下這三種檔案都可以被認為是 profile 的一部分
但是要注意的是只能有一個起作用
優先順序跟以下的順序相同
  1. ~/.bashrc
  2. ~/.bash_profile
  3. /etc/bash_profile
" ~/ " 代表 WINDOWS的使用者目錄下