git是一款分布式的版本控制软件,相比SVN,功能更强大,自然而然操作更复杂一些。git在本地也是以git版本库的形式管理,而SVN在本地管理的仅是一个版本库的副本。很明显的一个不同点:git你可以在本地做一些修改,然后commit到本地的版本库,最后push到服务器,而SVN只要一commit,更改就已经提交到服务器。
以下是git的一些常用操作:
查看命令帮助信息
# git help <command>
如:git help clone
设置name、email
# git config --global user.name LiXianlin
# git config --global user.email [email protected]
查看设置
# git config --list
克隆版本库
# git clone 版本库地址
# git clone 版本库地址 本地保存路径
创建版本库
# git init
检出/切换分支
# git checkout 分支名
如:git checkout master
创建并切换分支
# git checkout -b 分支名
查看分支
# git branch
创建分支
# git branch local
删除分支
# git branch -d local
添加文件
# git add 文件名或路径
删除文件
# git rm 文件名
提交
# git commit -m '提交备注信息'
设置远程版本库
# git remote add [-t <branch>] <name> <url>
如:git remote add -t master origin [email protected]:lixianlin/redis-cli.git
拉取远程版本库
# git pull <repo>
如:git pull origin
提交更改到远程服务器
# git push
查看tag
# git tag
创建tag
# git tag v1.0.1
删除tag
# git tag -d v1.0.1
提交tag
# git push --tags
撤消本地修改
# git reset --hard
删除远程tag
# git push origin :refs/tags/tag名称
如:git push origin :refs/tags/v1.0.1
查看日志
# git log
查看差异
# git diff
# git diff <file>
附:
git官方网站:http://git-scm.com/ 已被墙,可到http://download.chinaunix.net/download/0004000/3744.shtml下载