From : http://www.cnblogs.com/lexus/archive/2010/12/20/1911799.html
追求好的版本控制, 让开发变得更加简单是学习git的一个理由, 且git不会在每个目录下都生成.svn文件.分布式版本部署,强大的分支功能让我觉得git很有魅力.
使用git也会对我目前熟悉的开发工具产生些震荡, 要慢慢从windows下的开发转向linux的开发.
设置git默认文本编辑器
$ git config --global core.editor vi
设置解决合并冲突时使用哪种差异分析工具
$ git config --global merge.tool vimdiff
第一次下载,包括源码和版本库
git clone http://projectname 或 git clone git@gitserver:/projectname
下载服务器上最新的更新
git pull
检出某个修订版本
git reset –hard -r
新增被跟踪文件
git add /path/to/file
移除被跟踪文件
git rm /path/to/file
查看已暂存和未暂存的更新
$ git status
生成补丁
git diff >patch_file
提交
git commit git remote add origin git@gitserver:/home/git/w3cnotes.git
把一个git仓库放到你和你的同事都能用ssh访问,读写的服务器上, 就搭建好了一个git服务.
在ubuntu下安装git
$ apt-get instal git-core
在windows下安装git
请下载msysgit,下载地址http://code.google.com/p/msysgit/
都安装好了之后, 部署一个git代码仓库相当简单.进入项目目录/home/git/w3cnotes.git
1 .创建一个空的代码仓库
使用 –bare 选项运行 git init 来设定一个空仓库,这会初始化一个不包含工作目录的仓库
$ git init --bare
2. 把用户事先生成的公钥内容追加到authorized_keys 文件
完成这一步需要在你本机上进入SSH 公钥默认储存在账户的 ~/.ssh 目录
$$ cd ~/.ssh $ ls authorized_keys2 id_dsa known_hosts config id_dsa.pub
然后执行命令:
$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/Users/schacon/.ssh/id_rsa): id_rsa.yk Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /Users/schacon/.ssh/id_rsa. Your public key has been saved in /Users/schacon/.ssh/id_rsa.pub. The key fingerprint is: 43:c5:5b:5f:b1:f1:50:43:ad:20:a6:92:6a:1f:9a:3a schacon@agadorlaptop.local
这里我生成了id_rsa.yk.pub公钥, 并上传到服务器上的/tmp目录,追加到home/yk/.ssh/authorized_keys 文件后
$ cat /tmp/id_rsa.yk.pub >> ~/.ssh/authorized_keys
$ cd testgit $ git init $ git add . $ git commit -m 'initial commit' $ git remote add origin git@gitserver:/home/git/w3cnotes.git $ git push origin master
注:gitserver为服务器ip或域名,@前面为服务器用户.
$ git clone git@gitserver:/home/git/w3cnotes.git $ vim README $ git commit -am 'fix for the README file' $ git push origin master
git工具参考:
http://code.google.com/p/msysgit/
http://code.google.com/p/tortoisegit/
Cygwin
eclipse EGit
资料参考:
http://progit.org/book/zh
SVN,HG,GIT命令对照
loading