git学习笔记 推荐过来看看哈
2012-01-12 16:46
579 查看
转自: http://www.linuxso.com/linuxxitongguanli/11285.html
第一:git的介绍
Git是Linux之父创建的一个轻型的文件系统,目前最多的被用来作为版本控制,版本控制的基本原理是以牺牲磁盘空间(保存所有的历史版本,而不是保存差量的部分)来提高性能,同时可以很容易的创建分支(有利于合作开发)。git中存在三个区域(1、Repository
2、Working directory 3、Staging 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包含四个对象,分别是blob,tree和tag、commit(blob和tree对应,tree和commit对应,tag和commint对应),其实git的结构就是这几个对象所组成的一个树形结构,每个项目的版本在git中其实以commit的形式来保存,commit又指向tree,blob就好比tree的叶子,其实是保存数据部分的实体。另外git还包含指针HEAD,brance,HEAD唯一的指向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感觉十分的好用,在这里做一个系统的学习记录下来,以备工作时使用,再次感谢小布老师的无私授课。
第一:git的介绍
Git是Linux之父创建的一个轻型的文件系统,目前最多的被用来作为版本控制,版本控制的基本原理是以牺牲磁盘空间(保存所有的历史版本,而不是保存差量的部分)来提高性能,同时可以很容易的创建分支(有利于合作开发)。git中存在三个区域(1、Repository
2、Working directory 3、Staging 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包含四个对象,分别是blob,tree和tag、commit(blob和tree对应,tree和commit对应,tag和commint对应),其实git的结构就是这几个对象所组成的一个树形结构,每个项目的版本在git中其实以commit的形式来保存,commit又指向tree,blob就好比tree的叶子,其实是保存数据部分的实体。另外git还包含指针HEAD,brance,HEAD唯一的指向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感觉十分的好用,在这里做一个系统的学习记录下来,以备工作时使用,再次感谢小布老师的无私授课。
相关文章推荐
- 关于git笔记学习
- git 学习笔记4-git提交代码
- Ubuntu下Git配置学习笔记
- Git 学习笔记
- [学习笔记]git学习笔记之入门与常用git命令
- Git的学习笔记(一)——初识Git及版本库的管理
- 【Git学习笔记】将标签push到远程仓库
- CCNP学习笔记(4) 推荐
- Git学习笔记
- 个性化学习之推荐系统篇[笔记]
- 小五思科技术学习笔记之标准访问控制列表 推荐
- [学习笔记]git学习之fork的概念理解
- Git 学习笔记 -- Set up SSH for Git
- Git学习笔记
- [笔记分享] [Git] progit学习笔记之分支
- git学习笔记(本地仓库与github)
- Git学习笔记之git add
- 学习笔记——Git
- git学习笔记1-刚刚入门(霜之小刀)
- 【Git学习笔记】Git冲突:commit your changes or stash them before you can merge.