git实战-初步了解git

概述

Git 是一个版本控制工具。与常用的版本控制工具 CVS, Subversion 等不同,它采用了分布式版本库的方式,不必服务器端软件支持,使源代码的发布和交流极其方便。 Git 的速度很快,这对于诸如 Linux kernel 这样的大项目来说自然很重要。Git 最为出色的是它的合并跟踪(merge tracing)能力。

Git的历史

GitLinux的创始人Linus Tatvatds开发的开源和免费的版本管理系统,也称源代码管理系统(Source Code Manage,SCM). 它的官方网站是Http://git-scm.com

2005年的时候Linux核心开发小组和当时的他们的版本管理系统提供商产生分歧。他们不能再使用原有的版本管理系统了。当时Linus环顾宇宙之内竟然没有一个能满足自己需求的版本管理系统可用。于是他毅然决定自己动手开发一个!这就是Git。时至如今,Git已经成为许多著名系统的版本管理系统。比如Linux核心,EclipseAndroidRuby on RailsPostgreSQLjQuery……http://en.wikipedia.org/wiki/Git_(software)

Linus对这个版本控制开发时候的思考(特征):

Speed 速度(用C写的)

Simple design 简单设计

Strong support for non-linear development(thousands of parallel branches) 上千个分支

Fully distributed完全分布式

Able to handle large projects like the Linux kernel efficiently (speed and data size)

Git开发人员使用流程



 一般开发者,我就是Google Source Code使用者

扫描二维码关注公众号,回复: 1187122 查看本文章

a)         从服务器上克隆数据库(包括代码和版本信息)到单机上。

b)         在自己的机器上创建分支,修改代码。

c)         在单机上自己创建的分支上提交代码。

d)         在单机上合并分支。

e)         新建一个分支,把服务器上最新版的代码fetch下来,然后跟自己的主分支合并。

f)          生成补丁(patch),把补丁发送给主开发者。

g)         看主开发者的反馈,如果主开发者发现两个一般开发者之间有冲突(他们之间可以合作解决的冲突),就会要求他们先解决冲突,然后再由其中一个人提交。如果主开发者可以自己解决,或者没有冲突,就通过。

h)         一般开发者之间解决冲突的方法,开发者之间可以使用pull命令解决冲突,解决完冲突之后再向主开发者提交补丁。

主开发者的角度(假设主开发者不用开发代码):我就是Google Source code管理员

a)         查看邮件或者通过其它方式查看一般开发者的提交状态。

b)         打上补丁,解决冲突(可以自己解决,也可以要求开发者之间解决以后再重新提交,如果是开源项目,还要决定哪些补丁有用,哪些不用)。

c)         向公共服务器提交结果,然后通知所有开发者

Git的记录方式

Git是比快照而不是比不同

其他版本控制系统:



 Git,更像一个小型的文件系统:


Git文件的三个状态



 Committed:文件安全地存储在你的本地

Modified:你修改了文件,但还未提交到你的仓库

Staged:已经标记了一个已修改文件到下一个版本的快照

Git文件状态的生命周期


Untracked相当于SVN中图标为紫色问号那个状态,也就是还没和版本控制没什么关系的

Unmodified相当于SVN中图标为绝色打勾那个状态

modified相当于SVN中图标为红色感叹号那个状态

下载安装

git最新版是Git-1.7.11-preview20120710.exe

下载地址:http://msysgit.github.com/或者http://code.google.com/p/msysgit/downloads/list

安装就一路next就行了,在这里就不做说明。

打开命令行窗口Git Bash,输入“git help git”即可打开git的帮助文档

$ git help git

Launching default browser to display HTML ...

D:/Program/Git/doc/git/html/git.html

Git客户端tortoisegit,现在的最新版本是TortoiseGit-1.7.12.0-32bit.msi,下载地址:http://code.google.com/p/tortoisegit/,这个安装也一路NEXT,不作讲解

初步了解Git

配置项

1.       了解系统环境变量

/etc/gitconfig(D:/Program/Git/etc/gitconfig)

.gitconfig

2.       设置身份

$ git config --global user.name "yineng huang"

$ git config --global user.email [email protected]

3.       设置编辑器(可选)

$ git config –global core.editor emacs

4.       设置你的比较工具(可选)

$ git config –global merge.tool vimdiff

5.       检查你的配置(可选)

$ git config –list

$ git config --list

core.symlinks=false

core.autocrlf=true

color.diff=auto

color.status=auto

color.branch=auto

color.interactive=true

pack.packsizelimit=2g

help.format=html

http.sslcainfo=/bin/curl-ca-bundle.crt

sendemail.smtpserver=/bin/msmtp.exe

diff.astextplain.textconv=astextplain

rebase.autosquash=true

user.name=yineng huang

[email protected]

6.       帮助

$ git help

$ git --help

如:$ git help git

注,怎么如何以上配置是用什么命令呢?请参阅帮助文档:file:///D:/Program/Git/doc/git/html/git-config.html

几个区域

blessed(remote) repository:远程仓库

local repository:本地仓库

stage area:缓冲区-->git目录下的index文件

work area:工作区

我们现在用实例来描述一下这几个区域

huangyineng@HUANGYINENG-PC ~

$ mkdir gittest1

 

huangyineng@HUANGYINENG-PC ~

$ cd gittest1/

 

huangyineng@HUANGYINENG-PC ~/gittest1

$ git init

Initialized empty Git repository in c:/Users/huangyineng/gittest1/.git/

 

huangyineng@HUANGYINENG-PC ~/gittest1 (master)

$ echo "hello" >> hello

 

huangyineng@HUANGYINENG-PC ~/gittest1 (master)

$ git add .

warning: LF will be replaced by CRLF in hello.

The file will have its original line endings in your working directory.

 

huangyineng@HUANGYINENG-PC ~/gittest1 (master)

$ git commit hello -m "init hello"

warning: LF will be replaced by CRLF in hello.

The file will have its original line endings in your working directory.

[master (root-commit) 4d850bf] init hello

warning: LF will be replaced by CRLF in hello.

The file will have its original line endings in your working directory.

 1 file changed, 1 insertion(+)

 create mode 100644 hello

 

huangyineng@HUANGYINENG-PC ~/gittest1 (master)

$

以上命令的操作过程是:创建gittest1目录,进入该目录,把该目录初始化为仓库。这个仓库的具体位置是:C:\Users\huangyineng\gittest1\.git。创建创建一个文件(hello),把当然目录下的所有文件添加到缓冲区中,然后提交把hello文件提交到本地仓库中。

工作区就是gittest1目录(C:\Users\huangyineng\gittest1

缓冲区存放在.gitindex文件中(C:\Users\huangyineng\gittest1\.git\index

本地仓库会存放在.gitobjects目录下(C:\Users\huangyineng\gittest1\.git\objects

本文链接: http://www.656463.com/portal.php?mod=view&aid=69,转载请注明出处

猜你喜欢

转载自itway.iteye.com/blog/1636725