搞定Git中文乱码、用TortoiseMerge实现Diff/Merge、常见问题解决

来源:互联网 发布:最好吃的方便面知乎 编辑:程序博客网 时间:2024/06/08 01:26
首先要说明的是:这里介绍的方法都是大部分是本人“悟”出来的,所以网上难有流传!
好方法不能自己私藏,否则就白忙乎这几天了,分享给有需要的朋友们。如果有转载,敬请注明来自*CSDN老邓*作品。
呵呵,给自己打广告,实在是无耻之极,权当无聊之时打字之用。
欢迎流传,为最优秀的分布式版本管理系统Git做宣传!!

步骤:
1. 下载:http://loaden.googlecode.com/files/gitconfig.7z
2. 解压到:<MsysGit安装目录>/cmd/,例如:D:\Program Files\Git\cmd
3. 进入Bash,执行gitconfig

搞定什么了?

看看gitconfig的内容先:

#!/bin/sh # 全局提交用户名与邮箱git config --global user.name "Yuchen Deng"git config --global user.email 邮箱名@gmail.com # 中文编码支持echo "export LESSCHARSET=utf-8" > $HOME/.profilegit config --global gui.encoding utf-8git config --global i18n.commitencoding utf-8git config --global i18n.logoutputencoding gbk # 全局编辑器,提交时将COMMIT_EDITMSG编码转换成UTF-8可避免乱码git config --global core.editor notepad2 # 差异工具配置git config --global diff.external git-diff-wrapper.shgit config --global diff.tool tortoisegit config --global difftool.tortoise.cmd 'TortoiseMerge -base:"$LOCAL" -theirs:"$REMOTE"'git config --global difftool.prompt false # 合并工具配置git config --global merge.tool tortoisegit config --global mergetool.tortoise.cmd 'TortoiseMerge -base:"$BASE" -theirs:"$REMOTE" -mine:"$LOCAL" -merged:"$MERGED"'git config --global mergetool.prompt false # 别名设置git config --global alias.dt difftoolgit config --global alias.mt mergetool # 取消 $ git gui 的中文界面,改用英文界面更易懂if [ -f "/share/git-gui/lib/msgs/zh_cn.msg" ]; thenrm /share/git-gui/lib/msgs/zh_cn.msgfi


这个脚本解决了:

1. 中文乱码
2. 图形化Diff/Merge
3. 还原英文界面,更好懂
其中最有价值的,就是Git的Diff/Merge外部工具TortoiseMerge配置。
安装MsysGit后,一个命令即可完成配置。
适用于MsysGit安装版与绿色版。

网上关于为Git配置TortoiseMerge来进行diff和merge的介绍几乎没有(反正我没有搜索到),但我认为TortoiseMerge是最好用的,单文件(一个可执行程序,绿色版,下载地址:http://sourceforge.net/projects/tortoisesvn/files/Tools/1.6.7/TortoiseDiff-1.6.7.zip/download),实在是绝配!

为什么不使用TortoiseGit?他们不是集成了TortoiseMerge吗?
理由:TortoiseGit只有Windows才有,我更喜欢git gui,结合gitk,跨平台实在相同的操作方式,更爽!
如果您离不开TortoiseGit,这篇文章就直接无视吧。


PS:要把git-diff-wrapper.sh文件另外放到git安装目录下的bin目录下,才能正常使用git diff命令;

        要把notepad2文件另外放到git安装目录下的bin目录下,才能找到编辑器。

转载自:http://bbs.csdn.net/topics/360008711


[git] warning: LF will be replaced by CRLF


在window7下使用git的时候,建立一个新的库

git init

然后再把文件添加到库中

git add -A

但是出现了问他 提示:

warning: LF will be replaced by CRLF…..

解决办法:

在git bash  输入下面的命令:

git config --global core.autocrlf  false(2个’-')

gitcoreautocrlf

删掉项目中的.git文件夹 $  rm -rf .git

重新

git init  -》git add -A  问题解决!

下面是在Stack Overflow一位外国朋友的回答,阐述了为什么这样做。

/*add at 2012-03-13  解释为什么要按照上面做*/

Git has two modes of how it treats line endings:

$ git config core.autocrlf # that command will print either "true" or "false" 

You can set the mode to use by adding an additional parameter of true or false to the above command line.

If core.autocrlf is set to true, that means that any time you add a file to the git repo that git thinks is a text file, it will turn all CRLF line endings to just LF before it stores it in the commit. Whenever you git checkout something, all text files automatically will have their LF line endings converted to CRLF endings. This allows development of a project across platforms that use different line-ending styles without commits being very noisy because each editor changes the line ending style as the line ending style is always consistently LF.

The side-effect of this convenient conversion, and this is what the warning you’re seeing is about, is that if a text file you authored originally had LF endings instead of CRLF, it will be stored with LF as usual, but when checked out later it will have CRLF endings. For normal text files this is usually just fine. The warning is a “for your information” in this case, but in case git incorrectly assesses a binary file to be a text file, it is an important warning because git would then be corrupting your binary file.

If core.autocrlf is set to false, no line-ending conversion is ever performed, so text files are checked in as-is. This usually works ok, as long as all your developers are either on Linux or all on Windows. But in my experience I still tend to get text files with mixed line endings that end up causing problems.

My personal preference is to leave the setting turned ON, as a Windows developer.

http://stackoverflow.com/questions/1967370/git-replacing-lf-with-crlf


0 0
原创粉丝点击