windows实战Git环境配置msysGit+TortoiseGit(zz)

windows实战Git环境配置msysGit+TortoiseGit

发表于: 2010-08-17 14:46


查看: 2,047 次点击评论:0标签:git,msysgit,TortoiseGit分类:软件

Git是一个分布式源代码版本管理控制程序.“Git是一个由林纳斯·托瓦兹为了更好地管理linux内核开发而创立的分布式版本控制/软件配置管理软件。”- 维基百科中文。http://zh.wikipedia.org/zh-cn/Git

当msysgit和TortoiseGit的开发,如火如荼的进行着,我们可以在windows上使用的git,也越来越强大了。虽然远未达到如同在linux上一样强力。但足够打败其它版本控制系统了。

1. 它足够稳定,linux的核心就是用它来托管的。数G大的源码仓库,依然稳定如山。

2. 它足够快,是所有版本控制程序中最快的一个。

3. 它被人们所高度关注,有很多人为它写书,出教程。pro Git就是其中很好的一本书

4. 易学易用,几乎不存在门槛。

5. 无需花费成本,它是开源免费软件。

6. 跨平台,所有熟知的平台下面,都跑得很欢畅。

在介绍了一堆优点之后,让我们来进入Git的世界吧。linuxers 们,你们就不用看这里了。因为你们git骄子。linux下面铁定好使。windows下面的用户就需要自己动手,打造可用的git环境了。

感谢msysGit(http://code.google.com/p/msysgit/)和tortoiseGit(http://code.google.com/p/tortoisegit/)项目,让我们可以一次性装好所需的软件,而不用纯手动编译安装Git.

让我们按照先后顺序,下载msysgit 和tortoiseGit吧。

msysGit:http://msysgit.googlecode.com/files/Git-1.7.3.1-preview20101002.exe

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

更多版本下载:

MsysGit:http://code.google.com/p/msysgit/downloads/list?can=1&q=&colspec=Filename+Summary+Uploaded+ReleaseDate+Size+DownloadCount

TortoiseGit:http://code.google.com/p/tortoisegit/downloads/list?can=1&q=&colspec=Filename+Summary+Uploaded+ReleaseDate+Size+DownloadCount

下载完成后。先行安装msysgit,完毕后,再安装TortoiseGit.安装选项无妨使用。大家可以放心点下一步。

如果你不需要图形化界面,你甚至无需安装TortoiseGit,但是如果你跟我一样,还是喜欢TortoiseSVN的操作方式,你一定想安装TortoiseGit.

装上它们之后。需要重启一下系统。等windows重启后,你的电脑,己经可以使用git了。在桌面任意位置,点击鼠标右键,就应该可以看到TortoiseGit的菜单了。

尽情享用Git吧!

Git 系列之二:Windows 下 Git 客户端的选择,及msysGit 各种中文问题的解决-转载

Git 系列之二:Windows 下 Git 客户端的选择,及 msysGit 各种中文问题的解决

在 Windows 下用 NetBeans 做 PHP 开发,首先想到的是 NetBeans 的插件:NBGit。
评价:能用;若需没有的功能,可以自定义菜单调用自定义 bat 脚本;开发不活跃,使用没有信心。

第二个则是:TortoiseGit,SVN 小乌龟的 Git 版本。
评价:该有的功能基本都有了,还是不错的。

另外,TortoiseGit 只是 GUI 工具,使用它需要先安装 msysGit,这是正宗的 Git 之Windows 版本。msysGit 有个简单的 GUI 工具,及简单的 Explorer 集成;但它自带的 Bash 非常好用,深得 Linux 的真传。

选择:msysGit。
理由:
NBGit 不用说,功能都不完善,还需要自己定制 bat 脚本(若此,则它同样要依赖 msysGit);开发不活跃,很可能 NetBeans 下个版本更新就不能用了;况且,我们还有别的项目,不使用 NetBeans。

TortoiseGit 从功能上说是完善的,但它只是功能的堆砌而已,使用时完全体会不到 GUI 带来的便利。相反,它让人感觉很繁琐,一个劲地点鼠标,点来点去全是跟菜单打交道,远离了 Git 命令、远离了 Git 输出提示、远离了真相。

msysGit 的 Bash 非常好用;加上 Git 强大的 alias 功能,我们完全可以自定义一个 $ git go,使得 90% 的情况下只需要这一个命令,即使是不熟悉命令行的 Windows 用户也会觉得很好玩;因为 NBGit、TortoiseGit 都需要 msysGit 做底层,我们直接用底层工具也避免了上层 GUI 带来的额外的 bug。

需要的配置:

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

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

说明:使得在 Git Bash 中输入 ls 命令,可以正常显示中文文件名

2、C:\Program Files\Git\etc\inputrc:

set output-meta on
set convert-meta off

说明:使得在 Git Bash 中可以正常输入中文,比如中文的 commitlog。

3、C:\Program Files\Git\etc\profile:

export LESSCHARSET=utf-8

说明:$ git log 命令不像其它 vcs 一样,n 条 log 从头滚到底,它会恰当地停在第一页,按 space 键再往后翻页。这是通过将 log 送给 less 处理实现的。以上即是设置 less 的字符编码,使得 $ git log 可以正常显示中文。其实,它的值不一定要设置为 utf-8,比如 latin1 也可以……。还有个办法是$ git –no-pager log,在选项里禁止分页,则无需设置上面的选项。

4、C:\Program Files\Git\etc\gitconfig:
[alias]
go =
“! bash -c \”git pull && git add .; if [ \\\"$*\\\" ==\\\"\\\" ]; then git commit -a; else git commit -am \\\”$*\\\”; fi;git push origin master:your-id;\”"

说明:强大的 alias,有了这个,我们 90% 的情况下只需要输入 $ git go 这一个命令,免去了先拉后提交再推的繁琐步骤。

两种用法:
$ git go

$ git go aaa 修订说明

命令后带修订说明时,会直接提交。需要注意的是,在“修订说明”之前,有还个“aaa”,这是个 bug,参数中的第一个会被忽略,所以随便写一个凑数的……。

若命令行里没有提供修订说明,则会自动弹出一个编辑器,等待输入。默认的编辑器是 Vim。Vim 的使用是很简单的,首先要明白它有两个模式,一个是命令模式、一个是输入模式。Vim启动的时候默认的是命令模式,需要先按’i'键,进入输入模式;然后就正常编辑;编辑完成之后,将输入法切换回英文状态,按 Esc 重新进入命令模式;此时按 ‘(Shift):wq‘ 并回车,w 表示写入保存、q 表示退出。完毕!

若实在不习惯 Vim,也可以设置为其它编辑器:

$ git config --global core.editor "notepad"

其中 notepad 可以替换为更好用的 wordpad、notepad++ 等(不过它们在命令行里无法直接访问,得先设置 PATH 变量)。

以上 alias 是为 Windows 定制的,Linux 下可以写得更优雅,不过鉴于使用上没分别,就保持一致吧~。

[gui]
encoding = utf-8

说明:我们的代码库是统一用的 utf-8,这样设置可以在 gitgui 中正常显示代码中的中文。

[i18n]
commitencoding =GB2312

说明:如果没有这一条,虽然我们在本地用 $ git log 看自己的中文修订没问题,但,一、我们的 log 推到服务器后会变成乱码;二、别人在 Linux 下推的中文 log 我们 pull 过来之后看起来也是乱码。这是因为,我们的 commit log 会被先存放在项目的 .git/COMMIT_EDITMSG 文件中;在中文 Windows 里,新建文件用的是 GB2312 的编码;但是 Git 不知道,当成默认的 utf-8 的送出去了,所以就乱码了。有了这条之后,Git 会先将其转换成 utf-8,再发出去,于是就没问题了。

以上,给 Windows 下的同事在 Git Bash 里推代码就比较完美了。不过仍然有 3 个问题:

1、上面的 alias $ git go 有 bug,代码修订说明之前要输入一串字符凑数;

2、$ git diff,如果代码里有中文,会显示乱码;

3、$ git checkout 有时候需要修改/增删很多文件,如果某些文件被占用,会被 Windows 拒绝,导致失败,甚至可能造成版本库出现无法修复的问题。

这 3 个都是可承受的问题,前两个应该有办法解决;第 3 个归功于文件系统,只能尽量避免 checkout,实在需要的时候先注销一次,就不会有问题了。

【TIP】该文只是解释说明,具体操作请按《Windows 下 git 配置与使用指南》Wiki执行。

http://code.google.com/p/msysgit/issues/detail?id=345

What steps will reproduce the problem?
1. Setup Git and Gitosis on an Ubuntu server
2. Setup msysgit, PuTTY and TortoiseGit on Vista client
3. Setup 'git' user and 'gitosis-admin' project on server, and SSH keys on
client and server, according to standard install instructions
4. Clone the gitosis repository to local client system via the command:
git clone git@MY SERVER:gitosis-admin.git
 
What is the expected output?
Gitosis repository cloned to local Vista client
 
What do you see instead?
Server keeps asking for the 'git' user password, even though the 'git' user
was setup with 'password disabled' per instructions.
 
What version of the product are you using? On what operating system?
Server OS: Ubuntu 8.10 (32-bit)
Git: 1.5.6.3
 
Client OS: Vista Home Premium, Service Pack 2 (64-bit)
msysgit: 1.6.4.msysgit.0
PuTTY: 0.60
 
Please provide any additional information below.
Please help, or point me to clear install instructions for a Linux server
and Win clients (I originally tried a Windows 2003 server but this
dead-ended even sooner).
 
Git my be a superior tool, but setup outside pure Linux environments on
both client and server is like crawling blindly through a stinking mine
field. I hate to give up on git and go with Subversion, but if no progress
soon I will have to join the 'git sucks' camp, at least outside Linux.
 
Thanks for any help you can provide, I really need it!

Comment1byalexandr...@gmail.com,Oct 04, 2009

It seems to me like a ssh connection issue, try to connect to the ssh server using
putty and solve any errors that may appear.

Comment2byrory.roybal, Oct05, 2009

Thanks for your help.
 
However, what you suggested is exactly what I am already doing.
 
I am trying to connect to the ssh (Ubuntu in this case) server using PuTTY, and
although it connects to the server fine, the server still insists on a password for
the 'git' user *when the 'git clone ...' command is submitted*.
 
There is no error message, just asking for a password that doesn't exist and
shouldn't be required based on the 'git' user being set up with 'password disabled'.
 
Other ideas? Has anyone else encountered this symptom and/or found a solution??

Comment3byalexandr...@gmail.com,Oct 05, 2009

So you can connect with PuTTY and another user, but when you connect with PuTTY using
the "git" user then it fails? I'm asking because in my experience this kind of error
appears regardless of the user name used to connect.

Comment4by project memberJohannes...@gmail.com,Oct 05, 2009

Have you tested ssh from Ubuntu into the server? Does it ask for a password as 
well? If so, then it is a server-side (Ubuntu) issue and not a git-on-Windows 
issue.
 
BTW, if your server is next door (as opposed to across the Internet), I suggest you 
install Samba on Ubuntu and allocate your repositories in a directory that you 
export via Samba and that your Windows clients mount. But permission handling is, 
of course, vastly different from how gitosis does it.

Comment5byrory.roybal, Oct06, 2009

Thanks so much guys! You gave me the clues I needed to get past this hurdle.
 
I had not completely configured PuTTY with information it needed was the prob.
 
This is working now with no glitches.
 
Not finished setting up everything yet, but as least the SSL authentication and
cloning now works smoothly (I hope this was the most arcane part, seems like it).
 
I appreciate the help a lot!

Comment6by project memberjohannes...@googlemail.com,Oct 06, 2009

So I guess this was not an msysGit problem at all...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值