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

首先要说明的是:这里介绍的方法都是大部分是本人“悟”出来的,所以网上难有流传!
好方法不能自己私藏,否则就白忙乎这几天了,分享给有需要的朋友们。如果有转载,敬请注明来自*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/.profile
git config --global gui.encoding utf-8
git config --global i18n.commitencoding utf-8
git config --global i18n.logoutputencoding gbk
 
# 全局编辑器,提交时将COMMIT_EDITMSG编码转换成UTF-8可避免乱码
git config --global core.editor notepad2
 
# 差异工具配置
git config --global diff.external git-diff-wrapper.sh
git config --global diff.tool tortoise
git config --global difftool.tortoise.cmd 'TortoiseMerge -base:"$LOCAL" -theirs:"$REMOTE"'
git config --global difftool.prompt false
 
# 合并工具配置
git config --global merge.tool tortoise
git 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 difftool
git config --global alias.mt mergetool
 
# 取消 $ git gui 的中文界面,改用英文界面更易懂
if [ -f "/share/git-gui/lib/msgs/zh_cn.msg" ]; then
rm /share/git-gui/lib/msgs/zh_cn.msg
fi


这个脚本解决了:

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


前言 1. 什么是 TortoiseSVN? 2. TortoiseSVN 的特性 3. 许可协议 4. 开发 4.1. TortoiseSVN 的历史 4.2. 致谢 5. 阅读指南 6. 本文使用的术语 1. 开始 1.1. 安装 TortoiseSVN 1.1.1. 系统要求 1.1.2. 安装 1.2. 基本概念 1.3. 开始试用 1.3.1. 创建版本库 1.3.2. 导入项目 1.3.3. 检出工作副本 1.3.4. 进行修改 1.3.5. 添加更多的文件 1.3.6. 查看项目历史 1.3.7. 撤消更改 1.4. 继续前进 ... 2. 基本版本控制概念 2.1. 版本库 2.2. 版本模型 2.2.1. 文件共享的问题 2.2.2. 锁定-修改-解锁 方案 2.2.3. 复制-修改-合并 方案 2.2.4. Subversion 怎么做? 2.3. Subversion 实战 2.3.1. 工作副本 2.3.2. 版本库的 URL 2.3.3. 修订版本 2.3.4. 工作副本怎样跟踪版本库 2.4. 摘要 3. 版本库 3.1. 创建版本库 3.1.1. 使用命令行工具创建版本库 3.1.2. 使用 TortoiseSVN 创建版本库 3.1.3. 本地访问版本库 3.1.4. 访问网络共享磁盘上的版本库 3.1.5. 版本库布局 3.2. 版本库备份 3.3. 服务器端钩子脚本 3.4. 检出链接 3.5. 访问版本库 4. 日常使用指南 4.1. 基本特性 4.1.1. 图标重载 4.1.2. 右键菜单 4.1.3. 拖放 4.1.4. 常用快捷方式 4.1.5. 认证 4.1.6. 最大化窗口 4.2. 导入数据到版本库 4.2.1. 导入 4.2.2. 导入适当的位置 4.2.3. 专用文件 4.3. 检出工作副本 4.3.1. 检出深度 4.4. 将你的修改提交到版本库 4.4.1. 提交对话框 4.4.2. 修改列表 4.4.3. 从提交列表中排除项目 4.4.4. 提交日志信息 4.4.5. 提交进程 4.5. 用来自别人的修改更新你的工作副本 4.6. 解决冲突 4.6.1. 文件冲突 4.6.2. 属性冲突 4.6.3. 树冲突 4.6.3.1. 本地删除,当更新时有更改进入 4.6.3.2. 本地更改,当更新时有删除进入 4.6.3.3. 本地删除,当更新时有删除进入 4.6.3.4. 本地缺少,当合并时有更改进入 4.6.3.5. 本地更改,当合并时有删除进入 4.6.3.6. 本地删除,当合并时有删除进入 4.6.3.7. 其它树冲突 4.7. 获得状态信息 4.7.1. 图标重载 4.7.2. 详细状态 4.7.3. 在 Windows 资源管理器中的 TortoiseSVN 列 4.7.4. 本地与远程状态 4.7.5. 查看差别 4.8. 修改列表 4.9. 版本日志对话框 4.9.1. 调用版本日志对话框 4.9.2. 版本日志动作 4.9.3. 获得更多信息 4.9.4. 获取更多的日志信息 4.9.5. 当前工作副本的版本 4.9.6. 合并跟踪特性 4.9.7. 修改日志消息和作者 4.9.8. 过滤日志信息 4.9.9. 统计信息 4.9.9.1. 统计页 4.9.9.2. 作者提交次数统计页 4.9.9.3. 按日期提交统计页 4.9.10. 离线方式 4.9.11. 刷新视图 4.10. 查看差异 4.10.1. 文件差异 4.10.2. 行结束符和空白选项 4.10.3. 比较文件夹 4.10.4. 使用 TortoiseIDiff 进行比较的图像 4.10.5. Diffing Office Documents 4.10.6. 其他的比较/合并工具 4.11. 添加新文件和目录 4.12. 复制/移动/重命名文件和文件夹 4.13. 忽略文件和目录 4.13.1. 忽略列表中的模式匹配 4.14. 删除、移动和改名 4.14.1. 正在删除文件/文件夹 4.14.2. 移动文件和文件夹 4.14.3. 处理文件名称大小写冲突 4.14.4. 修复文件改名 4.14.5. 删除未版本控制的文件 4.15. 撤消更改 4.16. 清理 4.17. 项目设置 4.17.1. Subversion 属性 4.17.1.1. svn:keywords 4.17.1.2. 增加和编辑属性 4.17.1.3. 导出和导入属性 4.17.1.4. 二进制属性 4.17.1.5. 自动属性设置 4.17.2. TortoiseSVN 项目属性 4.17.3. 属性编辑器 4.17.3.1. 外部条目 4.17.3.2. SVN 关键字 4.17.3.3. EOL 样式 4.1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值