自动化部署之Git基础
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自动化部署之Git基础相关的知识,希望对你有一定的参考价值。
GIT基础
GIT是一个分布式版本管理系统,速度快,适合大规模,跨地区多人协同开。SVN是一个集中式版本管理系统。
(1)GIT生态
GIT分布式版本管理系统
Gitlab git私库解决方案
Github git公有库解决方案
(2)Git安装
Centos:
yum install -y git
Ubuntu:
apt-get install git
Windows安装git bash
Linux编译安装
注意不要使用git 1.8以下版本,推荐使用2.7版本
①编译安装git
[[email protected] ~]# yum install -y epel-release 安装依赖包: [[email protected] ~]# yum install -y curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker [[email protected] ~]# wget https://github.com/git/git/archive/v2.7.4.zip [[email protected] ~]# yum install -y unzip [[email protected] ~]# unzip git-v2.7.4.zip [[email protected] ~]# cd git-2.7.4 [[email protected] git-2.7.4]# make prefix=/usr/local/git all [[email protected] git-2.7.4]# make prefix=/usr/local/git install [[email protected] git-2.7.4]# rm -rf /usr/bin/git [[email protected] git-2.7.4]# ln -s /usr/local/git/bin/git /usr/bin/git [[email protected] git-2.7.4]# git --version git version 2.7.4 ②初始化仓库 [[email protected] ~]# mkdir test [[email protected] ~]# cd test [[email protected] test]# git init #将test目录初始化仓库 [[email protected] test]# git config --global user.name"*****" [[email protected] test]# git config --global user.email *******@qq.com 四个区域: 远程仓库<-->本地仓库<-->暂存区域<-->工作目录 四种状态 Untracked、Unmodified、Modified、Staged Untracked(工作目录)-->git add -->Staged(暂存区)-->git commit版本-->Unmodified(本地仓库)-->Edit file-->Modified-->Stage the file-->Staged ③常用命令: git add 加入暂存 git status 查看状态 git status -s 状态概览 git diff 尚未暂存的文件 git diff --staged 暂存区文件 git commit 提交更新 git reset 回滚 git rm 从版本库中移除 git rm --cached README 从暂存区中移除 git mv 相当于mv git rm git add 三个命令 使用演示: [[email protected] test]# touch index.html ==>创建文件 [[email protected] test]# vim index.html [[email protected] test]# git status ==>此时文件处于工作目录中 位于分支 master 初始提交 未跟踪的文件: (使用 "git add <文件>..." 以包含要提交的内容) index.html 提交为空,但是存在尚未跟踪的文件(使用 "git add" 建立跟踪) [[email protected] test]# git add index.html ==>加入代码库 [[email protected] test]# git status ==>此时文件处于暂存区 位于分支 master 初始提交 要提交的变更: (使用 "git rm --cached <文件>..." 以取消暂存) 新文件: index.html [[email protected] test]# git commit -m "first commit" ==>提交到本地仓库 [master(根提交) c6bc04f] first commit 1 file changed, 3 insertions(+) create mode 100644 index.html [[email protected] test]# git status 位于分支 master 无文件要提交,干净的工作区 [[email protected] test]# git log commit c6bc04f90d4ef442e2c4d5bc788b21de239332da ==>回滚需要的id Author: ****** <******@qq.com> Date: Fri Dec 8 22:37:40 2017 +0800 first commit [[email protected] test]# touch pay.html [[email protected] test]# vim pay.html [[email protected] test]# git add pay.html [[email protected] test]# git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: pay.html [[email protected] test]# touch news.html [[email protected] test]# echo "123" > news.html [[email protected] test]# git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: pay.html Untracked files: (use "git add <file>..." to include in what will be committed) news.html [[email protected] test]# git add news.html [[email protected] test]# git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: news.html new file: pay.html [[email protected] test]# git rm --cached pay.html #将pay.html从暂存区移除 rm 'pay.html' [[email protected] test]# git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: news.html Untracked files: (use "git add <file>..." to include in what will be committed) pay.html [[email protected] test]# git commit -m "news" [master d83603a] news 1 file changed, 1 insertion(+) create mode 100644 news.html [[email protected] test]# git status On branch master Untracked files: (use "git add <file>..." to include in what will be committed) pay.html nothing added to commit but untracked files present (use "git add" to track) [[email protected] test]# git log commit d83603a56b8926630d31b46898e4b6d69293d946 Author:******** Date: Fri Dec 8 22:48:37 2017 +0800 news commit c6bc04f90d4ef442e2c4d5bc788b21de239332da Author: ***************** Date: Fri Dec 8 22:37:40 2017 +0800 first commit [[email protected] test]# echo "66666" >> pay.html [[email protected] test]# git status On branch master Untracked files: (use "git add <file>..." to include in what will be committed) pay.html nothing added to commit but untracked files present (use "git add" to track) [[email protected] test]# git add pay.html [[email protected] test]# git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: pay.html [[email protected] test]# git commit -m "pay modelue" [master e55a302] pay modelue 1 file changed, 2 insertions(+) create mode 100644 pay.html [[email protected] test]# git status On branch master nothing to commit, working directory clean [[email protected] test]# git log commit e55a302e11d967fd25eac1cce8b6c7bed732019b Author:****************** Date: Fri Dec 8 22:49:57 2017 +0800 pay modelue commit d83603a56b8926630d31b46898e4b6d69293d946 Author: ****************** Date: Fri Dec 8 22:48:37 2017 +0800 news commit c6bc04f90d4ef442e2c4d5bc788b21de239332da Author: ****************** Date: Fri Dec 8 22:37:40 2017 +0800 first commit
2.分支管理
[[email protected] test]# git status On branch master nothing to commit, working directory clean 建分支,开发新功能是不能在master分支上开发 [[email protected] test]# git branch about #创建分支 [[email protected] test]# git status On branch master nothing to commit, working directory clean [[email protected] test]# git checkout about #切换分支 Switched to branch 'about' [[email protected] test]# git status On branch about nothing to commit, working directory clean [[email protected] test]# git log #创建的分支是在master分支当前的状态进行创建的。所以在about分支上也会有master的记录 commit e55a302e11d967fd25eac1cce8b6c7bed732019b Author: ************ Date: Fri Dec 8 22:49:57 2017 +0800 pay modelue commit d83603a56b8926630d31b46898e4b6d69293d946 Author: ************ Date: Fri Dec 8 22:48:37 2017 +0800 news commit c6bc04f90d4ef442e2c4d5bc788b21de239332da Author: ************ Date: Fri Dec 8 22:37:40 2017 +0800 first commit [[email protected] test]# git branch * about master [[email protected] test]# touch about.html [[email protected] test]# echo "about us" >> about.html [[email protected] test]# git add . [[email protected] test]# git commit -m "about" [about 08b200a] about 1 file changed, 1 insertion(+) create mode 100644 about.html [[email protected] test]# git log [[email protected] test]# git checkout master #切换到master分支 Switched to branch 'master' [[email protected] test]# git log [[email protected] test]# git checkout about #切换到about分支 [[email protected] test]# echo "about2" > about2.html [[email protected] test]# git add . [[email protected] test]# git commit -m "about2" [[email protected] test]# git log [[email protected] test]# git checkout master [[email protected] test]# git log [[email protected] test]# git merged about #在master分支上合并about分支 [[email protected] test]# git log [[email protected] test]# git branch test #创建test分支 [[email protected] test]# git checkout test [[email protected] test]# touch "test" > test.html [[email protected] test]# git add . [[email protected] test]# git commit -m "test" [[email protected] test]# git checkout master [[email protected] test]# git branch --merged #查看已经合并的分支 [[email protected] test]# git branch --no-merged #查看未合并的分支 分支命令 git branch例出分支 git branch -v git branch --merged查看哪些分支被合并 git branch --no-merged查看哪些分支未被合并 git branch -d testling删除分支 git checkout切换分支 git merged融合分支
以上是关于自动化部署之Git基础的主要内容,如果未能解决你的问题,请参考以下文章