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. Pod 生命周期和重启策略

    Pod 在整个生命周期中被系统定义为各种状态,熟悉 Pod 的各种状态对于理解如何设置 Pod 的调度策略.重启策略是很有必要的. Pod 的状态 状态值 描述 Pending API Server ...

  2. BugKu之备份是个好习惯

    题目:备份是个好习惯 思路分析 打开题目,看到一个字符串. 联系到题目,就猜到肯定是源代码泄露,用工具扫一下,发现了index.php.bak,验证了我的猜想,下载下来看看. <?php /** ...

  3. Java Logback简易教程

    本作品采用知识共享署名-非商业性使用 4.0 国际许可协议进行许可. 一.前言 本文以一个简单的项目为例,一步步展示logback的同步和异步配置方法,并且配置的日志要求满足阿里巴巴Java开发手册- ...

  4. Redis源码分析(adlist)

    源码版本:redis-4.0.1 源码位置: adlist.h : listNode.list数据结构定义. adlist.c:函数功能实现. 一.adlist简介 Redis中的链表叫adlist( ...

  5. EF Core 小技巧:迁移已经应用到数据库,如何进行迁移回退操作?

    场景描述:项目中存在两个迁移 Teacher 和 TeachingPlan ,TeachingPlan 在 Teacher 之后创建,并且已经执行 dotnet ef database update ...

  6. 谷粒 | 12 |easyExcel使用

    一.引入easyexcel依赖 <!--easyExcel依赖--> <dependency> <groupId>org.apache.poi</groupI ...

  7. 『学了就忘』Linux基础命令 — 35、网络中与其他机器通信的命令

    目录 1.write命令 2.wall命令 3.mail 命令 使用1:发送邮件 使用2:查看已经接收的邮件 使用3:发送文件内容 1.write命令 (1)write命令的基本信息 命令名称:wri ...

  8. S2-002漏洞分析

    漏洞概述 Struts2-002是一个 XSS 漏洞,该漏洞发生在 <s:url> 和 <s:a>标签中,未对标签内字符进行转义,当标签的属性 includeParams=al ...

  9. Android-ION内存管理简介

    ION内存管理简介 https://www.jianshu.com/p/4f681f6ddc3b http://kernel.meizu.com/memory%20management%20-%20i ...

  10. [bzoj1853]幸运数字

    容易发现幸运数字只有1024个,暴力标记倍数还是会tle的 容斥,即从中任选i个的lcm,复杂度为$o(2^1024)$ 剪枝一:当答案超过1024就不用算了 剪枝二:当某个数是另一个数的倍数时就删掉 ...