Git基本教程
来源:互联网 发布:软件的意思 编辑:程序博客网 时间:2024/05/18 15:07
说明
分布式的代码版本管理工具。
Git与你熟悉的大部分版本控制系统的差别是很大的。也许你熟悉Subversion、CVS、Perforce、Mercurial 等等,他们使用 “增量文件系统” (Delta Storage systems), 就是说它们存储每次提交(commit)之间的差异。Git正好与之相反,它会把你的每次提交的文件的全部内容(snapshot)都会记录下来。这会是在使用Git时的一个很重要的理念。
stage,--cached,index,一般都指暂存区
git的对象管理模型
主要通过commit对象,tree对象,blob对象,tag对象来管理各种提交。
通过一个SHA1来标识每个独立的对象。
commit对象:包含提交的作者,日期,提交log,以及指向的tree对象
tree对象:也类似一个文件目录索引对象,包含哥哥sub tree对象,以及目录的变化,以及blob对象
blob对象:本次文本变更的具体内容。
tag对象:简单的来说,就是针对一个commit对象增加一个标签
目录结构
$>tree -L 1
.
|-- HEAD # 这个git项目当前处在哪个分支里
|-- config # 项目的配置信息,git config命令会改动它
|-- description # 项目的描述信息
|-- hooks/ # 系统默认钩子脚本目录
|-- index # 索引文件
|-- logs/ # 各个refs的历史信息
|-- objects/ # Git本地仓库的所有对象 (commits, trees, blobs, tags)
`-- refs/ # 标识你项目里的每个分支指向了哪个提交(commit)。
基本用法
使用前的配置
设置用户名和邮件地址(commit log中会记录)
$ git config --global user.name “xx”
$ git config --global user.email xxx@xxx
设置一些命令缩写
$ git config --global alias.st status
$ git config --global alias.ci commit
$ git config --global alias.co checkout
$ git config --global alias.br branch
设置命令输出的颜色显示
$ git config --system color.ui true
查看Git设置(系统)
$ git config -l --system
查看Git设置(当前用户)
$ git config -l --global
查看Git设置(当前Git版本库)
$ git config -l --local
clone已经有的仓库
git clone http://www.kernel.org/pub/scm/git/git.gitgit clone username@host:/path/to/repository #没有配置username的情况下
本地的仓库,想纳入版本管理
$ tar xzf project.tar.gz
$ cd project
$ git init
正常的工作流
$git add file1
$git diff --cached
$git status
$ git commit
#补充说明
$ git commit -a 可以省略add 这步
分支与合并
#创建分支$ git branch experimental
#查看当前本地的分支
$ git branch
#切换分支
$ git checkout experimental
#现在分支中做修改,再切回master
(edit file)
$ git commit -a
$ git checkout master
#在master上再做一些修改
(edit file)
$ git commit -a
#合并两个分支
$ git merge experimental
#如果2个分支没冲突,就结束了,如果有冲突
$ git diff
#关于远程分支的补充$ git commit -a #编辑好后
$ gitk #图形界面查看历史记录#如果不需要该分支了
#撤销合并,慎用$ git branch -d experimental
$ git reset --hard ORIG_HEAD
#浏览远程分支#git pull不会主动创建本地分支,需要手动创建本地分支$git branch -r
$ git checkout –b <branchname> origin/<branchname>
查看历史 -Git日志
#查看某个担当具体的记录$git log --author=jacky --oneline
#显示补丁,会详细现实每个commit和之前的commit之间的差异
$git log -p
#现实最近2周的提交
$ git log --since="2 weeks ago" # commits from the last 2 weeks
#显示修改某个文件的提交$ git log Makefile # commits that modify Makefile
$ git log fs/ # commits that modify any file under fs/
#日志统计$ git
log --no-merges # dont show merge commits$ git log -S'foo()' # commits that add or remove any file data # matching the string 'foo()'
$ git log --stat
#格式化日志$ git log --pretty=onelinea6b444f570558a5f31ab508dc2a24dc34773825f dammit, this is the second time this has reverted49d77f72783e4e9f12d1bbcacc45e7a15c800240 modified index to create refs/heads if it is not 9764edd90cf9a423c9698a2f1e814f16f0111238 Add diff-lcs dependencye1ba1e3ca83d53a2f16b39c453fad33380f8d1cc Add dependency for Open40f87b4d9020fff756c18323106b3fd4e2f422135 merged recent changes: * accepts relative alt patf0ce7d5979dfb0f415799d086e14a8d2f9653300 updated the Manifest file
$ git log --pretty=short
commit a6b444f570558a5f31ab508dc2a24dc34773825f
Author: Scott Chacon <schacon@gmail.com>
dammit, this is the second time this has reverted
commit 49d77f72783e4e9f12d1bbcacc45e7a15c800240
Author: Scott Chacon <schacon@gmail.com>
modified index to create refs/heads if it is not there
commit 9764edd90cf9a423c9698a2f1e814f16f0111238
Author: Hans Engel <engel@engel.uk.to>
Add diff-lcs dependency
$ git log --pretty=format:'%h was %an, %ar, message: %s'a6b444f was Scott Chacon, 5 days ago, message: dammit, this is the second time this has re49d77f7 was Scott Chacon, 8 days ago, message: modified index to create refs/heads if it i9764edd was Hans Engel, 11 days ago, message: Add diff-lcs dependencye1ba1e3 was Hans Engel, 11 days ago, message: Add dependency for Open40f87b4d was Scott Chacon, 12 days ago, message: merged recent changes:
$ git log --pretty=format:'%h : %s' --graph* 2d3acf9 : ignore errors from SIGCHLD on trap* 5e3ee11 : Merge branch 'master' of git://github.com/dustin/grit|\ | * 420eac9 : Added a method for getting the current branch.* | 30e367c : timeout code and tests* | 5a09431 : add timeout protection to grit* | e1193f8 : support for heads with slashes in them|/ * d6016bc : require time for xmlschema
#日志排序
$ git log --pretty=format:'%h : %s' --topo-order --graph
$ git log --pretty=format:'%h : %s' --date-order --graph
参照资料
- 快速入门
- 中文介绍网站
- Git 教程 - Git 基本用法
- Git 教程 - Git 基本用法
- Git 教程 - Git 基本用法
- Git 教程 - Git 基本用法
- Git 教程 - Git 基本用法
- Git 教程 - Git 基本用法
- Git 教程 - Git 基本用法
- Git 教程 - Git 基本用法
- Git 教程 - Git 基本用法
- Git基本教程
- git的基本教程
- GIT基本教程
- Git的基本教程
- Git基本使用教程
- git基本使用教程
- 【Git 教程(5)】 Git基本操作
- Git 简洁教程之:基本操作
- Git----基本使用详解及进阶教程
- 优点汇总最自豪的事情“一”
- yii 模型
- cocos2d-x 通过python模板方式新建支持lua的工程
- Makefile选项CFLAGS,LDFLAGS,LIBS
- Java内部类的使用小结
- Git基本教程
- Python学习6:动态类型与共享引用
- Qt圆角窗体+半透明背景+右下角显示(移除窗体标题栏+置顶+不在任务栏显示)
- ASS特效字幕自学记录01
- 8 arrayadapter的原理和使用
- 黑马程序员笔记:Java基础知识之位运算--两变量值交换方法
- ubuntu下配置tomcat
- LeetCode - Reverse Integer
- test