GIT(分布式版本控制系统)
2015-06-16 20:57
330 查看
1. 简介
Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件2. GIT和SVN的区别
GIT是分布式的,SVN不是还有一些系统,例如Bitkeeper, Mercurial等,也是运行在分布式模式上的。但GIT在这方面做的更好,而且有更多强大的功能特征
分布式模式,如果你被困在一个不能连接网络的地方时,你仍然能够提交文件,查看历史版本记录,创建项目分支等
GIT把内容按元数据方式存储,而SVN是按文件
.git目录的体积大小跟.svn比较
它拥有中心版本库上所有的东西,例如标签,分支,版本记录等
GIT分支和SVN的分支不同
GIT没有一个全局的版本号,而SVN有
GIT的内容完整性要优于SVN
GIT的内容存储使用的是SHA-1哈希算法。这能确保代码内容的完整性,确保在遇到磁盘故障和网络问题时降低对版本库的破坏
3. 下载
http://git-scm.com/downloads4. linux安装
//Debian/Ubuntu $ apt-get install git //Fedora $ yum install git //Gentoo $ emerge --ask --verbose dev-vcs/git //Arch Linux $ pacman -S git //openSUSE $ zypper install git //FreeBSD $ cd /usr/ports/devel/git $ make install //Solaris 11 Express $ pkg install developer/versioning/git //OpenBSD $ pkg_add git
5. git配置
Git的config命令或者直接编辑~/.gitconfig$ git config --global user.name "Your Name" $ git config --global user.email "email@example.com"
$ git config --list //查看配置
[user] name = userid emal = userid@heartsone.net [color] status = auto branch = auto ui = auto
color在git diff时,显示红色和绿色
6. 创建一个ssh key
$ ssh-keygen -C 'your@email.address' -t dsa /root/.ssh/id_dsa.pub #linux /c/Users/administrator/.ssh/id_rsa.pub #windows
dsa:指定加密类型
7. 拷贝id_rsa.pub内的公钥到
8. 配置域名解析
c:\windows\system32\drivers\etc\hosts //windows /etc/hosts //linux //添加 192.168.70.130 gerrit.hbu.com
9. 连接成功后
首先要配置name和email,否则,git review时邮箱匹配不上。邮箱需要登录验证,即自动保存10. git常用命令
#添加 $ git add <file> # 将工作文件修改提交到本地暂存区 $ git add . # 将所有修改过的工作文件提交暂存区 $ git add -f # force
#提交 $ git commit $ git commit -a # 可以将那些没有通过git add标识的变化一并强行提交,不建议使用这种方式 $ git commit -m "有意义的附加说明" $ git commit --amend # 新的提交来覆盖上一次的提交
#回退 $ git reset head~ $ git checkout a.txt # 撤销a.txt的修改
#删除 $ git rm <file> # 从版本库中删除文件 $ git rm <file> --cached # 从版本库中删除文件,但不删除文件。适用于一次添加了很多文件, 却又想排除个别几个文件的情况。必须在当前路径
#查看diff $ git diff <file> # 比较当前文件和暂存区文件差异 $ git diff <id1><id2> # 比较两次提交之间的差异
#查看提交记录 $ git log git log <file> # 查看该文件每次提交记录 $ git log -p <file> # 查看每次详细修改内容的diff $ git log -p -2 # 查看最近两次详细修改内容的diff
#git远程分支 $ git pull = fetch + merge # 抓取远程仓库所有分支更新并合并到本地 $ git fetch origin # 抓取远程仓库更新。不会自动merge,比Git pull更安全些 $ git merge origin/master # 将远程主分支合并到本地当前分支
#git远程仓库 $ git remote -v # 查看远程服务器地址和仓库名称 $ git remote add origin ssh://admin@gerrit.hbu.com # 添加远程仓库地址 $ git remote set-url origin <repository> # 设置远程仓库地址(用于修改远程仓库地址) $ git remote rm <repository> # 删除远程仓库
# review代码 $ pip install git-review $ git review //windows $ git-review //linux
windows 安装python-3.4.3.msi;linux 安装pip。python安装见专题
此时,即可看到review记录
11. git的忽略机制
一些文件是不希望接受Git 管理,写到.gitignore 文件中12. git分支
$ git branch -a * master remotes/origin/HEAD -> origin/master
一个叫 origin 的远程库的 master 分支
13. git换行符
Windows下开发,建议设置autocrlf为trueUTF8并且包含中文文字,那还是把autocrlf设置为false
Linux/Unix LF \n MacOS CR \r
AutoCRLF
//提交时转换为LF,检出时转换为CR $ git config --global core.autocrlf true //提交时转换为LF,检出时不转换 $ git config --global core.autocrlf input //提交检出均不转换 $ git config --global core.autocrlf false
SafeCRLF
//拒绝提交包含混合换行符的文件 $ git config --global core.safecrlf true //允许提交包含混合换行符的文件 $ git config --global core.safecrlf false //提交包含混合换行符的文件时给出警告 $ git config --global core.safecrlf warn
14. Change-Id错误
remote: ERROR: missing Change-Id in commit message remote: Suggestion for commit message: remote: Cosmetic improvements to PostreSQL updater output remote: remote: * Don't WARN on sequences already existing remote: * Align dots nicely to the rest remote: (cherry picked from commit bd7a268e4be2da23ba0b9943c3b0ba1ac88294dc) remote: remote: Change-Id: Ia354acd879c3dd840e7be1e3c6d6fc78d696631d To ssh://saper@review:29418/mediawiki/core.git ! [remote rejected] HEAD -> refs/for/REL1_19/PostgreSQL (missing Change-Id in commit message) error: failed to push some refs to 'ssh://saper@review:29418/mediawiki/core.git'
解决办法:
$ git cherry-pick -n bd7a268e4be2da23ba0b9943c3b0ba1ac88294dc $ git commit -c bd7a268e4be2da23ba0b9943c3b0ba1ac88294dc
remote: Resolving deltas: 100% (1/1) remote: Processing changes: refs: 1, done remote: ERROR: missing Change-Id in commit message footer remote: Suggestion for commit message: remote: [*][*][*][NA]fix bug[*5] remote: remote: Change-Id: I53***80 remote: remote: Hint: To automatically insert Change-Id, install the hook: remote: gitdir=$(git rev-parse --git-dir); scp -p -P port name@hostIp:hooks/commit-msg ${gitdir}/hooks/
解决办法:
$ gitdir=$(git rev-parse --git-dir); scp -p -P port name@hostIp:hooks/commit-msg ${gitdir}/hooks/ $ git commit --amend
15. 冲突处理
<<<<<<< HEAD test in master ======= test in dev >>>>>>> dev
对于简单的合并,手工编辑,然后去掉这些标记,add再commit即可
相关文章推荐
- java中的自动装箱和自动拆箱
- struts2 counter循环标签的使用
- HDU 1151 Air Raid(最小路径覆盖)
- Spring Jdbc
- [算法]java实现 二分查找 斐波那契数列 静静思考
- linux下导入、导出mysql数据库命令
- 进程管理(四)
- 7-6
- 婴幼儿乳制品和钙的摄入建议--澳洲相关育儿经验分享
- Linux下Tomcat的启动、关闭、杀死进程
- Lucene源码解析--IndexWriterConfig配置参数说明
- hdu 1281 棋盘游戏
- ZH奶酪:Python 中缀表达式转换后缀表达式
- OC学习--文件操作
- Lua5.3 注册表 _G _ENV
- s:iterator的用法
- 解决删除后返回到原jsp但是内容没有取到的处理方法
- Android APP线程是由谁创建的
- bzoj1816二分答案 扑克牌
- tiny linux: 内核精简的根文件系统制作