1. 简介

1.1. 版本控制工具:

本地版本控制系统:

集中化版本控制系统:CVS,SVN

分布式版本控制系统: BitKeeper,Git

1.2. 官方网站:

https://git-scm.com

1.3. Git基本结构

工作区:Workding Directory

暂存库:Staging Area

版本库: Repository

1.4. Git仓库包含索引(暂存)和对象库(版本库)

1.5. 相关文档

免费的ebook: https://git-scm.com/book/zh/v2

1.6.Git的对象类型

块(blob)对象:文件的每个版本表现为一个块(blob)

树(tree)对象:一个目录代表一层目录信息

提交(commit)对象:用于保存版本库一次变化的元数据,包括作者、邮箱、提交日期、日志;每个提交对象都指定一个目录树对象

标签(tag)对象:用于给一个特定对象一个易读的名称;

1.7. Git的文件分类

已追踪的(tracked):已经在版本库中,或者已经使用git add命令添加至索引中的文件;

被忽略的(Ignored):在版本库中通过“忽略文件列表”明确声明为被忽略的文件;

未追踪的(untracked):上述两类之外的其他文件;

2. Git简单使用

2.1. git init

~]cd /root
~]mkdir myproject
~]cd myproject
~]git init
~]# tree .git
.git
├── branches
├── config
├── description
├── HEAD
├── hooks
│   ├── applypatch-msg.sample
│   ├── commit-msg.sample
│   ├── post-update.sample
│   ├── pre-applypatch.sample
│   ├── pre-commit.sample
│   ├── prepare-commit-msg.sample
│   ├── pre-push.sample
│   ├── pre-rebase.sample
│   └── update.sample
├── info
│   └── exclude
├── objects
│   ├── info
│   └── pack
└── refs
├── heads
└── tags 9 directories, 13 files

2.2. git config

##添加全局配置参数
git config --global user.sex male
git config --global user.name eric ##添加本地配置参数
git config --add user.mail eric@123 ##这个是全局参数,在用户家目录下
~]# pwd
/root
~]# ls -al .gitconfig
-rw-r--r-- 1 root root 20 Aug 7 04:13 .gitconfig
~]# cat .gitconfig
[user]
name = eric
sex = male
~]# git config -l --global
user.name=eric
user.sex=male ##这个是本地参数,在项目目录下
~]# pwd
/root/myproject/.git
~]# ls -al config
-rw-r--r-- 1 root root 116 Aug 7 04:57 config
~]# git config -l --local
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
user.mail=eric@123
~]# cat config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[user]
mail = eric@123

#还有一个系统级的在/etc/gitconfig
~]# git config -l --system

2.3. git add

git add . #暂存当前目录所有
git add DIR #暂存指定DIR

2.4. git commit

提交的标识:

  引用:ID,reference,SHA1,绝对提交名

  符号引用:symbolic reference,symref;

    本地特性分支名称、远程跟踪分支名称、标签名;

    名称:

      refs/heads/REF:本地特性分支名称

      refs/remotes/REF:远程跟踪分支名称

      refs/tags/REF:标签名

git会自动维护几个特定目的的特殊符号引用:

  HEAD:始终指向当前分支的最近提交;或检出到其他分支时,目标分支的最近提交;

  ORIG_HEAD:合并操作时,新生成的提交之前的提交保存于此引用中;

  FETCHED_HEAD:

  MERGE_HEAD:合并操作时,其他分支的上一次提交;

#add不add都可以commit,但是commit之前要指定email和user
~]# git commit -m "v0.1" *** Please tell me who you are. Run git config --global user.email "you@example.com"
git config --global user.name "Your Name" #再次提交
~]# git commit -m "v0.1"
[master (root-commit) 3c56c9b] v0.1
1 file changed, 1 insertion(+)
create mode 100644 readme.md

2.5. git clone

#可以clone本地或者远程的项目
~]# git clone myproject/ Newmyproject
Cloning into 'Newmyproject'...
done.

2.6. git status

# 已经提交或者刚创建
~]# git status
# On branch master
nothing to commit, working directory clean # 修改一下
~]# echo "installation" >> install.sh
~]# git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# install.sh
nothing added to commit but untracked files present (use "git add" to track) # 保存一下
~]# git add install.sh
~]# git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: install.sh
# #提交一下
~]# git commit -m "v0.2"
[master 19cb183] v0.2
1 file changed, 1 insertion(+)
create mode 100644 install.sh
~]# git status
# On branch master
nothing to commit, working directory clean

  

2.7. 文件相关

git ls-files:默认显示索引中的文件列表的原始文件名;

      -s:显示暂存的文件信息,;权限、对象名、暂存号及原始文件名;

      -o:显示未被追踪的文件

      --unmerged:只查看未合并的文件

git cat-file

git rm:删除工作目录中的文件,及索引中的映射;

  --cached:只删除索引中的映射

git mv:改变工作目录中的文件名,及索引中的映射


~]# git ls-files -s
100644 3100e23cd38ef12583bfc792b5c62aea7e9dbaca 0 install.sh
100644 3b18e512dba79e4c8300dd08aeb37f8e728b8dad 0 readme.md ~]# git cat-file -p 3100e23cd38ef12583bfc792b5c62aea7e9dbaca
installation

  

2.8. git log

git log --graph --pretty=oneline --abbrev-commit

~]# git log
commit 19cb183c7270e8fe4015f11e7d712372ba40c3b4
Author: eric <eric@1234.com>
Date: Tue Aug 7 07:38:17 2018 +0200 v0.2 commit 3c56c9bd0bf1600982e0af01540e96207276f136
Author: eric <eric@1234.com>
Date: Tue Aug 7 05:11:50 2018 +0200 v0.1

  

2.9. git diff

~]# git diff --color 3c56c9bd0bf1600982e0af01540e96207276f136 19cb183c7270e8fe4015f11e7d712372ba40c3b4
diff --git a/install.sh b/install.sh
new file mode 100644
index 0000000..3100e23
--- /dev/null #老文件
+++ b/install.sh #新文件
@@ -0,0 +1 @@
+installation

  

2.10. git reset:撤销此前的操作;

  --soft:将HEAD引用指向给定的提交,但不影响索引和工作目录;

  --mixed:将HEAD引用指向指定的提交,并将索引内容改变为指定提交的快照;但不改变工作目录;

  --hard:将HEAD引用指向给定的提交、将索引内容改变为指定提交的快照,并改变工作目录中的内容反映指定提交的内容

2.11. git branch:列出、创建及删除分支

  git branch BRANCH_NAME [START_COMMIT]

  git branch -d BRANCH_NAME

2.12. git show-branch:查看分支及其相关的提交

2.13. git checkout:在分支间切换

    git checkout <branch>:检出分支

2.14. git merge BRANCK_NAME #需要checkout到master

3. git服务器

3.1. 支持的协议:本地协议(local)、HTTP/HTTPS协议、SSH协议、Git协议

3.2. 本地协议:

git clone file:///path/to/repo.git /path/to/local/server

git clone /path/to/repo.git /path/to/local/server

  

3.3. Git协议:由git-deamon程序提供,监听在tcp的9418端口;仅支持“读”操作,无任何认证功能;

git://host/path/to/repo.git

git://host/~user/path/to/repo.git

  

3.4. SSH协议:

ssh://[USER@]host[:port]/path/to/repo.git

ssh://[USER@]host[:port]/~USERNAME/path/to/repo.git

[USER@]host/path/to/repo.git

  

3.5. HTTP/HTTPS协议:在1.6.5之前的版本为哑http协议,只能读不能写,不能认证,在1.6.6之后的版本为智能http协议,可读可写可认证

http://host/path/to/repo.git #这是一个映射的地址,并不是服务器真实的路径

  

3.6.引用远程版本库:

远程版本库是定义在配置文件中的一个实体,在配置文件中体现为[remote "NAME"],它由两部分组成,URL+refspec(定义一个版本库与其他版本库的名称空间的映射关系)

+source:destination
refs/heads/NAME:本地分支
refs/remotes/NMAE:远程跟踪分支 [remote "publis"]
url = http://HOST/pub/repo_name.git
push = + refs/heads/*:refs/remote/origin/* remote.publish.url
remote.publish.push

  

3.7. git remote命令:管理远程仓库

4. git服务器

4.1. 安装必要的包

yum install -y git-daemon httpd

  

4.2. 检查httpd安装

# 修改http配置文件
~]# sed "s/\<ServerName/ServerName YOURSERVERIP:80/g" /etc/httpd/conf/httpd.conf # alias,cgi,env这三个模块必须要有
~]# httpd -M |grep -Ei "\<(alias|cgi|env)"
alias_module (shared)
env_module (shared)
cgi_module (shared)

~]# systemctl start httpd

  

4.3. 检查git-deamon安装

~]# cat /usr/lib/systemd/system/git@.service
[Unit]
Description=Git Repositories Server Daemon
Documentation=man:git-daemon(1) [Service]
User=nobody
ExecStart=-/usr/libexec/git-core/git-daemon --base-path=/var/lib/git --export-all --user-path=public_git --syslog --inetd --verbose
StandardInput=socket

~]# systemctl start git.socket

  

【Linux】【Services】【VersionControl】Git基础概念及使用的更多相关文章

  1. Git基础概念与Flow流程介绍

    目录 Git相关 基本概念 常见客户端 TortoiseGit Sourcetree Intellij Idea 命令行 常用命令 存储区域 命令之 add & commit &pus ...

  2. Git基础-第2章

    简单的Git基础概念: repository: 仓库 track:  跟踪 stage: 暂存 commit:    提交 push:        推送 pull:    拉取 一.获取Git仓库 ...

  3. Git基础和入门

    一.Git基础概念 Git功能简单概述 可以随时回滚到之前的代码版本(git reset --hard ): 协同开发时不会覆盖别人的代码(分支): 留下修改记录(git log): 发版时可以方便的 ...

  4. linux设备驱动归纳总结(二):模块的相关基础概念【转】

    本文转载自:http://blog.chinaunix.net/uid-25014876-id-59415.html linux设备驱动归纳总结(二):模块的相关基础概念 系统平台:Ubuntu 10 ...

  5. linux设备驱动归纳总结(一)内核的相关基础概念【转】

    本文转载自:http://blog.chinaunix.net/uid-25014876-id-59413.html linux设备驱动归纳总结(一):内核的相关基础概念 xxxxxxxxxxxxxx ...

  6. (转载)小白的linux设备驱动归纳总结(一):内核的相关基础概念---学习总结

    1. 学习总结 小白的博客讲的linux内核驱动这一块的东西比较基础,因此想通过学习他的博客,搭配着看书的方式来学习linux内核和驱动.我会依次更新在学习小白的博客的过程的感悟和体会. 2.1 内核 ...

  7. 【Linux开发】linux设备驱动归纳总结(二):模块的相关基础概念

    linux设备驱动归纳总结(二):模块的相关基础概念 系统平台:Ubuntu 10.04 开发平台:S3C2440开发板 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ...

  8. 【Linux开发】linux设备驱动归纳总结(一):内核的相关基础概念

    linux设备驱动归纳总结(一):内核的相关基础概念 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ...

  9. Git详解之二 Git基础

    Git 基础 读完本章你就能上手使用 Git 了.本章将介绍几个最基本的,也是最常用的 Git 命令,以后绝大多数时间里用到的也就是这几个命令.读完本章,你就能初始化一个新的代码仓库,做一些适当配置: ...

随机推荐

  1. 【代码更新】单细胞分析实录(21): 非负矩阵分解(NMF)的R代码实现,只需两步,啥图都有

    1. 起因 之前的代码(单细胞分析实录(17): 非负矩阵分解(NMF)代码演示)没有涉及到python语法,只有4个python命令行,就跟Linux下面的ls grep一样的.然鹅,有几个小伙伴不 ...

  2. 【java+selenium3】Tesseract-OCR识别图片验证码 (十六)

    [java+selenium+Tesseract-OCR(图片识别)+AutoIt(windows窗口识别)]完成自动化图片验证码识别! 一.AutoIt(windows窗口识别)参考:https:/ ...

  3. 【java+selenium3】隐式等待+显式等待 (七)

    一.隐式等待 -- implicitlyWait 调用方式:driver.manage().timeouts().implicitlyWait(long time, TimeUnit unit); / ...

  4. 经过4次优化我把python代码耗时减少95%

    背景交代 团队做大学英语四六级考试相关服务.业务中有一个care服务,购买了care服务考试不过可以全额退款,不过有一个前提是要完成care服务的任务,比如坚持背单词N天,完成指定的试卷. 在这个背景 ...

  5. 深入理解Spring IOC容器

    本文将从纯xml模式.xml和注解结合.纯注解的方式讲解Spring IOC容器的配置和相关应用. 纯XML模式 实例化Bean的三种方式: 使用无参构造函数 默认情况下,会使用反射调用无参构造函数来 ...

  6. 来了!公开揭密团队成员开发鸿蒙 OpenHarmony 的完整过程(收获官方7000奖金和开发板等,1w字用心总结)

    背景 随着 OpenHarmony 组件开发大赛结果公布,我们的团队成员被告知获得了二等奖,在开心之余也想将我们这段时间宝贵的开发经验写下来与大家分享,当我们看到参赛通知的时候已经是 9 月中旬的时候 ...

  7. silky微服务框架服务注册中心介绍

    目录 服务注册中心简介 服务元数据 主机名称(hostName) 服务列表(services) 终结点 时间戳 使用Zookeeper作为服务注册中心 使用Nacos作为服务注册中心 使用Consul ...

  8. python-内置函数(搭配lambda使用)

    目录 常用的内置函数 需要注意的知识点: enumerate()函数 map()函数 zip()函数 filter()函数 reduce()函数 sum()函数 max()/ min()函数 sort ...

  9. [noi712]练级

    先考虑一个联通块,可以发现这个联通快内不会存在两个偶数的点证明:如果存在,那么这两个点的某一条路径上的边全部反过来,可以使答案+2,即答案为点数或点数-1同时,发现答案的奇数点数一定与边数同奇偶,那么 ...

  10. watch异步操作

    异步操作: 1.ajax, 2.定时器 3.点击事件 4.数据库操作 特点:代码不等待,后续代码会继续执行. watch:{ //watch作用监测已经存在的数据 newVal 新值,oldVal 旧 ...