美文网首页
2019-03-04 Git基础

2019-03-04 Git基础

作者: 阿丧小威 | 来源:发表于2019-03-05 23:17 被阅读0次

1. Git简介

  • linus用C语言编写
  • 2005年诞生
  • 分布式版本管理系统
  • 速度快,适合大规模,跨地区多人协同开发

2. 本地版本管理

本地版本管理

2.1 集中式

集中式

2.2 分布式

分布式

3. Git生态

  • Git分布式版本管理系统
  • Gitlab git私库解决方案
  • Github git公有库解决方案

4. Git安装

  • CentOS
    yum install git(这种方法安装版本太旧)
  • Ubuntu
    apt-get install git
  • Windows安装git bash
  • Linux编译安装(注意不要使用git1.8以下版本,推荐使用2.7以上版本
CentOS示例:
[root@localhost ~]# yum install -y epel-release
[root@localhost ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker -y    ---安装依赖
[root@localhost ~]# wget https://github.com/git/git/archive/v2.7.4.zip -O git-2.7.4.zip    ---下载git
[root@localhost ~]# unzip git-2.7.4.zip     ---解压
[root@localhost ~]# cd git-2.7.4/
[root@localhost git-2.7.4]# make prefix=/usr/local/git all    ---编译
[root@localhost git-2.7.4]# make prefix=/usr/local/git install    ---安装
[root@localhost git-2.7.4]# vi /etc/profile
export $PATH=/usr/local/git/bin/$PATH    ---在最后面添加这行
:wq
[root@localhost git-2.7.4]# source /etc/profile
[root@localhost git-2.7.4]# git --version
git version 2.7.4
初始化git:
[root@localhost test]# mkdir test
[root@localhost test]# cd test/
[root@localhost test]# git init
[root@localhost test]# git config --global user.name "zheng"
[root@localhost test]# git config --global user.email zheng@qq.com
[root@localhost test]# git config --list
user.name=zheng
user.email=zheng@qq.com
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true

5. Git原理

四个区域 四种状态 常用命令

示例1:

root@localhost ~]# cd test/
[root@localhost test]# touch index.html
[root@localhost test]# vi index.html 
<h1>hello world</h1>
:wq
[root@localhost test]# git status
On branch master
Initial commit
Untracked files:    ---未被追踪文件
  (use "git add <file>..." to include in what will be committed)
    index.html
nothing added to commit but untracked files present (use "git add" to track)
[root@localhost test]# git add index.html     ---添加进代码库
[root@localhost test]# git status
On branch master
Initial commit
Changes to be committed:    ---在这个下面的就为暂存区里
  (use "git rm --cached <file>..." to unstage)    ---文件已经在暂存区里,要撤回来的话用“git rm --cached <file>”
    new file:   index.html
[root@localhost test]# git commit -m "first commit"    ---提交到本地仓库
[master (root-commit) b613f50] first commit
 1 file changed, 1 insertion(+)
 create mode 100644 index.html
[root@localhost test]# git status
On branch master
nothing to commit, working directory clean    ---工作目录为空
[root@localhost test]# git log
commit b613f505626d37c74b262ba5a345ef41740785fb    ---ID
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:33:08 2019 +0800
    first commit

示例2:

创建第二个文件:
[root@localhost test]# touch test.html
[root@localhost test]# vi test.html 
Hello World
:wq
[root@localhost test]# git add test.html 
[root@localhost test]# git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)
    new file:   test.html
[root@localhost test]# touch news.html
news
:wq
[root@localhost test]# git add news.html 
[root@localhost test]# git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)
    new file:   news.html
    new file:   test.html    ---假设这个没开发完,需要撤回来
[root@localhost test]# git rm --cached test.html     ---撤回来
rm 'test.html'
[root@localhost 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)
    test.html    ---被拉回去工作目录了
[root@localhost test]# git commit -m "news"    ---把没问题的news提交
[master 8ce4e28] news
 1 file changed, 1 insertion(+)
 create mode 100644 news.html
[root@localhost test]# git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
    test.html
nothing added to commit but untracked files present (use "git add" to track)
[root@localhost test]# vi test.html     ---修改bug
Hello World
fixed bug    ---修改内容
:wq
[root@localhost test]# git add test.html 
[root@localhost test]# git commit -m "test"
[master 8880be9] test
 1 file changed, 2 insertions(+)
 create mode 100644 test.html
[root@localhost test]# git log
commit 8880be9fc12c00fe8f5a26a5f87e6b6af193ac7b
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:43:44 2019 +0800
    test
commit 8ce4e28510f0bdf1153c064e507b11e2b2052744
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:41:12 2019 +0800
    news
commit b613f505626d37c74b262ba5a345ef41740785fb
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:33:08 2019 +0800
    first commit

相关文章

  • 2019-03-04 Git基础

    1. Git简介 linus用C语言编写 2005年诞生 分布式版本管理系统 速度快,适合大规模,跨地区多人协同开...

  • 2.Git初步

    Git是什么 Git是什么 Git基础 Git基础 1. 下载安装Git GIT官网 安装好后,按win+R 输入...

  • Git总结

    初步 下载git 基础配置: 基础操作 获取Git仓库 初始化现有仓库 git init 克隆远程仓库 git c...

  • Git基本操作

    一、 git的基础操作 基础操作 1.在项目里创建一个git : $ git init 链接远程项目: $ git...

  • git操作

    git基础命令: git commit ---- 提交git branch newBranchName --- 新...

  • Git

    关于版本控制 Git 简史 Git 基础 安装 Git Git 前的配置

  • 2.3 Git 基础 - 查看提交记录

    提交记录git log 2.2 Git 基础 - 记录每次更新到仓库(删除和改名)2.4 Git 基础 - 撤销操...

  • 面试中的那些 Git 问题 - 基础部分

    面试中的那些 Git 问题 - 基础部分 面试中的那些 Git 问题 - 基础部分

  • 2016-06-24 阅读整理

    Git Git 基础命令Git 分支管理Git 分支合并Git 公钥提交Git 常用技巧Git 设置别名 Andr...

  • Git 系列文章

    GIT 初识 Git的基础操作 Git的远程操作 Git的分支管理 Git标签操作 Git团队协作 Git 多账户...

网友评论

      本文标题:2019-03-04 Git基础

      本文链接:https://www.haomeiwen.com/subject/itxguqtx.html