【Linux】【Services】【VersionControl】Git基础概念及使用
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基础概念及使用的更多相关文章
- Git基础概念与Flow流程介绍
目录 Git相关 基本概念 常见客户端 TortoiseGit Sourcetree Intellij Idea 命令行 常用命令 存储区域 命令之 add & commit &pus ...
- Git基础-第2章
简单的Git基础概念: repository: 仓库 track: 跟踪 stage: 暂存 commit: 提交 push: 推送 pull: 拉取 一.获取Git仓库 ...
- Git基础和入门
一.Git基础概念 Git功能简单概述 可以随时回滚到之前的代码版本(git reset --hard ): 协同开发时不会覆盖别人的代码(分支): 留下修改记录(git log): 发版时可以方便的 ...
- linux设备驱动归纳总结(二):模块的相关基础概念【转】
本文转载自:http://blog.chinaunix.net/uid-25014876-id-59415.html linux设备驱动归纳总结(二):模块的相关基础概念 系统平台:Ubuntu 10 ...
- linux设备驱动归纳总结(一)内核的相关基础概念【转】
本文转载自:http://blog.chinaunix.net/uid-25014876-id-59413.html linux设备驱动归纳总结(一):内核的相关基础概念 xxxxxxxxxxxxxx ...
- (转载)小白的linux设备驱动归纳总结(一):内核的相关基础概念---学习总结
1. 学习总结 小白的博客讲的linux内核驱动这一块的东西比较基础,因此想通过学习他的博客,搭配着看书的方式来学习linux内核和驱动.我会依次更新在学习小白的博客的过程的感悟和体会. 2.1 内核 ...
- 【Linux开发】linux设备驱动归纳总结(二):模块的相关基础概念
linux设备驱动归纳总结(二):模块的相关基础概念 系统平台:Ubuntu 10.04 开发平台:S3C2440开发板 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ...
- 【Linux开发】linux设备驱动归纳总结(一):内核的相关基础概念
linux设备驱动归纳总结(一):内核的相关基础概念 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ...
- Git详解之二 Git基础
Git 基础 读完本章你就能上手使用 Git 了.本章将介绍几个最基本的,也是最常用的 Git 命令,以后绝大多数时间里用到的也就是这几个命令.读完本章,你就能初始化一个新的代码仓库,做一些适当配置: ...
随机推荐
- CentOS7自动备份oracle数据库
1.环境 操作系统:CentOS 7 数据库:11.2.0.1.0 2.登录服务器 切换oracle用户,备份需要在oracle用户下进行 #su - oracle 在oracle家目录下创建bin目 ...
- 【mysql3】我的大学teacher课程进行中|持续更新系列!
1.做一下powerdesigner的画图 2.所有的创建表格 .....1 修改字段的数据类型:alter table 表名 modify 字段名 新数据类型; 修改字段名: alter table ...
- Linux下安装、配置、启动与访问RabbitMQ
一.下载 首先第一步要下载三个rpm安装包,为了方便安装与学习,给出下载途径 网盘网址:https://pan.baidu.com/s/18Z64Lb9KQpRh10RzqZBdoQ 提取码:094v ...
- 后台管理系统:vue&node&MongoDB(一)
后台管理系统 使用工具: Vue Node Mongodb Element-ui 一.后台(Node+Mongodb) 前期准备: 需要下载的包: mongooes -------- ...
- Spring Boot 面试总结
1.使用 Spring Boot 前景? 多年来,随着新功能的增加,spring变得越来越复杂.只需访问https://spring.io/projects页面,我们就会看到可以在我们的应用程序中使用 ...
- C# 两个具有相同属性的类赋值
最近有遇到两个类之间的赋值问题,两个类的属性几乎都一样的,所以写了个通过反射获取属性的然后赋值的方法,把一个类的属性的值赋值给另一个类. 框架是.net 4.5 public static D Map ...
- soft and hard limit
soft限制了资源使用上限; soft可调整; hard限制了soft上限; 普通用户可使用ulimit -H调低hard limit. 限制的是一个进程可用资源, 而不是某个用户总和. man se ...
- OWASP-Top5-(Security Misconfiguration 安全配置错误)
概述 从上一版的第 6 位开始,90% 的应用程序都经过了某种形式的错误配置测试.随着更多转向高度可配置的软件,看到这一类别上升也就不足为奇了.值得注意的CWE包括CWE-16 Configurati ...
- [cf611H]New Year and Forgotten Tree
首先,来构造这棵树的形态 称位数相同的点为一类点,从每一类点中任选一个点,具有以下性质: 1.每一类中选出的点的导出子图连通(是一颗树) 2.每一条边必然有一个端点属于某一类中选出的点 (关于&quo ...
- Taro 3.4 beta 发布: 支持 Preact 为应用开辟更多体积空间
项目体积是困扰小程序开发者的一大问题,如果开发者使用 Taro React 进行开发,更是不得不引入接近 100K 的 React 相关依赖,这让项目体积变得更加捉襟见肘.因此,Taro v3.4 的 ...