git学习笔记 推荐过来看看哈

来源:互联网 发布:八个字的网络流行语 编辑:程序博客网 时间:2024/05/16 01:48

转自: http://www.linuxso.com/linuxxitongguanli/11285.html


第一:git的介绍

GitLinux之父创建的一个轻型的文件系统,目前最多的被用来作为版本控制,版本控制的基本原理是以牺牲磁盘空间(保存所有的历史版本,而不是保存差量的部分)来提高性能,同时可以很容易的创建分支(有利于合作开发)。git中存在三个区域(1Repository 2Working directory 3Staging area / Index, Repository(缺省的是以.git为名字的目录,意思就是可以自己自定义名字)可以比喻为一个仓库或者说数据库,因为以后所有的代码都要存放其中,Working directory很好理解,就是开发的环境(比如用于书写代码的那个目录),Staging area

/ Index是一个中间(代码从Working directory提交到Repository中)的状态。具体命令过程是:git add .代表把代码从Working directory提交到Staging area / Index另外一个命令:git commit –m “注释代表从Staging area / Index提交到Repository  综合这两个步骤的快捷命令是:git commit –a。另外git包含四个对象,分别是blobtreetagcommitblobtree对应,treecommit对应,tagcommint对应),其实git的结构就是这几个对象所组成的一个树形结构,每个项目的版本在git中其实以commit的形式来保存,commit又指向treeblob就好比tree的叶子,其实是保存数据部分的实体。另外git还包含指针HEADbranceHEAD唯一的指向commit.

想详尽的了解git请去网络搜索了解。

 

第二:git的下载和安装

下载的部分在官网下载即可,这里下载的是git-1.7.7.4.tar.gz

[root@localhost ~]# tar zxvf git-1.7.7.4.tar.gz

[root@localhost ~]# cd git-1.7.7.4

[root@localhost git-1.7.7.4]# ./configure

[root@localhost git-1.7.7.4]# make && make install

安装好之后查看以上没加入.configure时的默认安装目录

[root@localhost ~]# which git   //这个路径在PATH内,故不需要再添加

/usr/local/bin/git

这样git就安装成功了

 

第三:git的基本配置(这里root登录)

[root@localhost /]# mkdir -p /git/project

[root@localhost /]# cd /git/project/

[root@localhost project]# git config --global user.name 'ethnicitybeta'

[root@localhost project]# git config --global user.email 'ethnicitybeta@126.com'

Global的配置其实是写入用户的家目录中的git配置文件中

[root@localhost project]# cat ~/.gitconfig

[user]

       name = ethnicitybeta

       emal = ethnicitybeta@126.com

       email =

[root@localhost project]# vim main.c   //创建测试文件

 

Hello ethnicitybeta!!!

 [root@localhost project]# git init    //git的初始化

Initialized empty Git repository in /git/project/.git/

[root@localhost project]# ls -al

total 32

drwxr-xr-x 3 root root 4096 Nov 27 03:38 .

drwxr-xr-x 3 root root 4096 Nov 27 03:11 ..

drwxr-xr-x 7 root root 4096 Nov 27 03:38 .git

-rw-r--r-- 1 root root   23 Nov 27 03:37 main.c

接下来这段是相对于全局设置的局部设置

[root@localhost project]# git config user.name 'ethniciy'

[root@localhost project]# git config user.email 'ethnicity@126.com'

[root@localhost project]# cat .git/config

[core]

       repositoryformatversion = 0

       filemode = true

       bare = false

       logallrefupdates = true

[user]

       email = ethnicity@126.com

       name = ethnicity

第四:一个git实例

[root@localhost project]# vim main.c   //创建测试文件

 

Hello ethnicitybeta!!!

[root@localhost project]# git init    //git的初始化

[root@localhost project]# git add .   //加入到git

[root@localhost project]# ll .git/    //下边出现的index就是Staging area

total 72

-rw-r--r-- 1 root root   23 Nov 27 03:38 HEAD

drwxr-xr-x 2 root root 4096 Nov 27 03:38 branches

-rw-r--r-- 1 root root  143 Nov 27 03:41 config

-rw-r--r-- 1 root root   73 Nov 27 03:38 description

drwxr-xr-x 2 root root 4096 Nov 27 03:38 hooks

-rw-r--r-- 1 root root  104 Nov 27 03:43 index

drwxr-xr-x 2 root root 4096 Nov 27 03:38 info

drwxr-xr-x 5 root root 4096 Nov 27 03:43 objects

[root@localhost project]# git commit -m '1st commit'  //提交生成第一个commit

[master (root-commit) 96f025b] 1st commit

 1 files changed, 1 insertions(+), 0 deletions(-)

 create mode 100644 main.c

[root@localhost project]# rm -rf main.c    //模拟一个文件丢失

[root@localhost project]# git checkout -f HEAD  //找回丢失的文件

[root@localhost project]# ls

main.c

 

总结:之前有接触版本控制的概念,仅有的名词概念是svn,还没来得及做研究,这里接触了git感觉十分的好用,在这里做一个系统的学习记录下来,以备工作时使用,再次感谢小布老师的无私授课。  

原创粉丝点击