博客为日常工作学习积累总结:

1.升级git版本:

参考博客:https://blog.csdn.net/yuexiahunone/article/details/78647565由于新的版本可以使用gitea功能所以升级git版本,centos7默认git版本如下:

[root@git ~]# git --version
git version 1.8.3.1

2.yum默认安装不适合生成环境需要编译安装此步奏忽略:

yum命令安装git是最简单的,直接键入命令安装就可以了

yum install git -yy

3.编译安装:

yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker

wget https://github.com/git/git/archive/v2.9.5.zip

unzip v2.9.5.zip

cd git-2.9.5

make prefix=/usr/local/git all

make prefix=/usr/local/git install

rm -rf /usr/bin/git

ln -s /usr/local/git/bin/git /usr/bin/git

git --version

[root@git git-2.9.5]# git --version
git version 2.9.5

4.初始化:

[root@git ~]# git config

git help

[root@git ~]# mkdir test

[root@git ~]# cd test/

[root@git learngit]# git init
Initialized empty Git repository in /root/learngit/.git/

[root@git learngit]# git config --list
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true

5.配置git目录:

[root@git learngit]# git config --global user.name "Eric-xgc"
[root@git learngit]# git config --global user.email 741017474@qq.com

[root@git learngit]# git config --list
user.name=Eric-xgc
user.email=741017474@qq.com
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true

6.git应用原理:

图片来源老男孩教育郭宏泽

git add

git status

git status -s

git diff

git diff --staged

git commit

git reset

git rm

git rm --cached README

git mv

7.测试命令功能:

1.初始化后

[root@git test]# git status
On branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)

2.新增一个文件

[root@git test]# vim index.html
<h1>welcome to ht <h1>

[root@git 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)

3.提交一个文件到暂存区

[root@git test]# git add index.html
[root@git test]# git status        
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

new file:   index.html

4.提交到本地仓库

[root@git test]# git commit -m "first commit"
[master (root-commit) 6083db0] first commit
 1 file changed, 1 insertion(+)
 create mode 100644 index.html

[root@git test]# git status
On branch master
nothing to commit, working tree clean

5.查看提交日志

[root@git test]# git log
commit 6083db06d756ef50053cb439e55144242f95b5a8
Author: Eric-xgc <741017474@qq.com>
Date:   Mon Apr 1 14:31:43 2019 +0800

first commit

6.测试rm命令

[root@git test]# vim pay.html
pay modle

[root@git test]# git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

new file:   pay.html

[root@git test]# vim news.html
news center

[root@git test]# git add news.html

[root@git 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

[root@git test]# git rm --cached pay.html
rm 'pay.html'

[root@git 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

[root@git test]# git commit -m "news"
[master 33a1733] news
 1 file changed, 1 insertion(+)
 create mode 100644 news.html
[root@git test]# git log
commit 33a17331c4060afd85d303dccad8406f8c74037b
Author: Eric-xgc <741017474@qq.com>
Date:   Mon Apr 1 14:46:44 2019 +0800

news

commit 6083db06d756ef50053cb439e55144242f95b5a8
Author: Eric-xgc <741017474@qq.com>
Date:   Mon Apr 1 14:31:43 2019 +0800

first commit

[root@git 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)

[root@git test]# vim pay.html
pay modle

22222222
bug

[root@git test]# git add pay.html
[root@git test]# git commit -m "pay"
[master 2e667e5] pay
 1 file changed, 4 insertions(+)
 create mode 100644 pay.html

[root@git test]# git log
commit 2e667e57e89b6794592563c14ae52cf2da3c8736
Author: Eric-xgc <741017474@qq.com>
Date:   Mon Apr 1 14:48:54 2019 +0800

pay

commit 33a17331c4060afd85d303dccad8406f8c74037b
Author: Eric-xgc <741017474@qq.com>
Date:   Mon Apr 1 14:46:44 2019 +0800

news

commit 6083db06d756ef50053cb439e55144242f95b5a8
Author: Eric-xgc <741017474@qq.com>
Date:   Mon Apr 1 14:31:43 2019 +0800

first commit

7.分支管理

业务场景:当需要开发新的模块时会经常改动代码,不能影响主分支master

创建分支:about

git branch about

[root@git test]# git branch about

切换分支

git checkout about

[root@git test]# git checkout about
Switched to branch 'about'

[root@git test]# git status
On branch about
nothing to commit, working tree clean

测试分支与主分支:

[root@git test]# vim about.html
about us

[root@git test]# git add .

[root@git test]# git commit -m "about"

测试about分支有4次提交

[root@git test]# git log
commit 6a24c259931e8401ac46448d4873f77eae167de9
Author: Eric-xgc <741017474@qq.com>
Date:   Mon Apr 1 15:46:34 2019 +0800

about

commit 2e667e57e89b6794592563c14ae52cf2da3c8736
Author: Eric-xgc <741017474@qq.com>
Date:   Mon Apr 1 14:48:54 2019 +0800

pay

commit 33a17331c4060afd85d303dccad8406f8c74037b
Author: Eric-xgc <741017474@qq.com>
Date:   Mon Apr 1 14:46:44 2019 +0800

news

commit 6083db06d756ef50053cb439e55144242f95b5a8
Author: Eric-xgc <741017474@qq.com>
Date:   Mon Apr 1 14:31:43 2019 +0800

first commit

切回主分支查看log只有3次提交

[root@git test]# git checkout master
Switched to branch 'master'
[root@git test]# git log
commit 2e667e57e89b6794592563c14ae52cf2da3c8736
Author: Eric-xgc <741017474@qq.com>
Date:   Mon Apr 1 14:48:54 2019 +0800

pay

commit 33a17331c4060afd85d303dccad8406f8c74037b
Author: Eric-xgc <741017474@qq.com>
Date:   Mon Apr 1 14:46:44 2019 +0800

news

commit 6083db06d756ef50053cb439e55144242f95b5a8
Author: Eric-xgc <741017474@qq.com>
Date:   Mon Apr 1 14:31:43 2019 +0800

first commit

回到测试分支

[root@git test]# git checkout about
Switched to branch 'about'
[root@git test]# git branch
* about
  master

[root@git test]# git branch -v
* about  6a24c25 about
  master 2e667e5 pay

8. 将测试分支合并到主分支:

[root@git test]# vim about2.html
about2

[root@git test]# git add .
[root@git test]# git commit -m "about2"
[about 0283739] about2
 1 file changed, 1 insertion(+)
 create mode 100644 about2.html

测试分支有5次提交
[root@git test]# git log
commit 02837391d9b360902f8599ca91ad83eaf2560324
Author: Eric-xgc <741017474@qq.com>
Date:   Mon Apr 1 15:55:49 2019 +0800

about2

commit 6a24c259931e8401ac46448d4873f77eae167de9
Author: Eric-xgc <741017474@qq.com>
Date:   Mon Apr 1 15:46:34 2019 +0800

about

commit 2e667e57e89b6794592563c14ae52cf2da3c8736
Author: Eric-xgc <741017474@qq.com>
Date:   Mon Apr 1 14:48:54 2019 +0800

pay

commit 33a17331c4060afd85d303dccad8406f8c74037b
Author: Eric-xgc <741017474@qq.com>
Date:   Mon Apr 1 14:46:44 2019 +0800

news

commit 6083db06d756ef50053cb439e55144242f95b5a8
Author: Eric-xgc <741017474@qq.com>
Date:   Mon Apr 1 14:31:43 2019 +0800

first commit

主分支还是3次提交

[root@git test]# git checkout master
Switched to branch 'master'
[root@git test]# git log
commit 2e667e57e89b6794592563c14ae52cf2da3c8736
Author: Eric-xgc <741017474@qq.com>
Date:   Mon Apr 1 14:48:54 2019 +0800

pay

commit 33a17331c4060afd85d303dccad8406f8c74037b
Author: Eric-xgc <741017474@qq.com>
Date:   Mon Apr 1 14:46:44 2019 +0800

news

commit 6083db06d756ef50053cb439e55144242f95b5a8
Author: Eric-xgc <741017474@qq.com>
Date:   Mon Apr 1 14:31:43 2019 +0800

first commit

将测试分支merge到主分支:

[root@git test]# git merge about
Updating 2e667e5..0283739
Fast-forward
 about.html  | 1 +
 about2.html | 1 +
 2 files changed, 2 insertions(+)
 create mode 100644 about.html
 create mode 100644 about2.html

查看主分支log

[root@git test]# git checkout master
Already on 'master'
[root@git test]# git log
commit 02837391d9b360902f8599ca91ad83eaf2560324
Author: Eric-xgc <741017474@qq.com>
Date:   Mon Apr 1 15:55:49 2019 +0800

about2

commit 6a24c259931e8401ac46448d4873f77eae167de9
Author: Eric-xgc <741017474@qq.com>
Date:   Mon Apr 1 15:46:34 2019 +0800

about

commit 2e667e57e89b6794592563c14ae52cf2da3c8736
Author: Eric-xgc <741017474@qq.com>
Date:   Mon Apr 1 14:48:54 2019 +0800

pay

commit 33a17331c4060afd85d303dccad8406f8c74037b
Author: Eric-xgc <741017474@qq.com>
Date:   Mon Apr 1 14:46:44 2019 +0800

news

commit 6083db06d756ef50053cb439e55144242f95b5a8
Author: Eric-xgc <741017474@qq.com>
Date:   Mon Apr 1 14:31:43 2019 +0800

first commit

查看被merged的分支:

[root@git test]# git branch --merged
  about
* master

[root@git test]# git branch --no-merged

[root@git test]# git branch test
[root@git test]# git branch --merged   
  about
* master
  test

[root@git test]# vim test.html
test

testi1

[root@git test]# git add .
[root@git test]# git commit -m "test2"

[root@git test]# git branch --merged
  about
* master
[root@git test]# git branch --no-merged
  test

退出git log

在英文状态下按q退出

9.checkerout命令

git checkerout  命令:用于切换分支。

[root@git test]# git checkout master

回滚本地目录修改的文件

git checkerout  -- 修改的文件

git checkout -- index.html

测试用例:

[root@git test]# vim index.html
<h1>welcome to ht <h1>

[root@git test]# git status     
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

modified:   index.html

no changes added to commit (use "git add" and/or "git commit -a")

[root@git test]#  git checkout -- index.html
[root@git test]# git status                  
On branch master
nothing to commit, working tree clean

修改被撤销了,

[root@git test]# cat index.html
<h1>welcome to ht <h1>

10.reset 回滚暂存区修改的文件

git log得到的id号
git reset --hard id号

所有的操作记录

[root@git test]# git reflog
0283739 HEAD@{0}: checkout: moving from test to master
3a525df HEAD@{1}: checkout: moving from master to test
0283739 HEAD@{2}: checkout: moving from test to master
3a525df HEAD@{3}: commit: test2
eed3382 HEAD@{4}: commit: test
0283739 HEAD@{5}: checkout: moving from master to test
0283739 HEAD@{6}: checkout: moving from master to master
0283739 HEAD@{7}: merge about: Fast-forward
2e667e5 HEAD@{8}: checkout: moving from about to master
0283739 HEAD@{9}: commit: about2
6a24c25 HEAD@{10}: checkout: moving from master to about
2e667e5 HEAD@{11}: checkout: moving from about to master
6a24c25 HEAD@{12}: commit: about
2e667e5 HEAD@{13}: checkout: moving from master to about
2e667e5 HEAD@{14}: commit: pay
33a1733 HEAD@{15}: commit: news
6083db0 HEAD@{16}: commit (initial): first commit

git checkout   6083db0

8.远程仓库

[root@git ~]# git clone https://github.com/guohongze/scripts.git

[root@git ~]# cd scripts/
[root@git scripts]# ls
mysql  nfs  nginx  php  README.md  redis  svn  zookeeper

[root@git scripts]# git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean

[root@git scripts]# git commit -m "readme update-eric"
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
        modified:   README.md

no changes added to commit
[root@git scripts]# git remote
origin
[root@git scripts]# git remote -v
origin  https://github.com/guohongze/scripts.git (fetch)
origin  https://github.com/guohongze/scripts.git (push)

[root@git scripts]# git push origin master

/root/learngit/test

[root@git test]# git remote add orgin https://github.com/Eric-xgc/test.git
[root@git test]# git remote -v
orgin   https://github.com/Eric-xgc/test.git (fetch)
orgin   https://github.com/Eric-xgc/test.git (push)

打标签:

[root@git test]# git tag -a v1.0 -m "feature finished"
[root@git test]# git tag
v1.0

06.升级git版本及命令学习的更多相关文章

  1. Centos7升级Git版本

    centos 升级 Git 版本 问题描述 centos7 系统默认的 git 安装版本是 1.8,但是在项目构建中发现 git 版本过低,于是用源码编译的方式进行升级.同时该文章也适用于安装新的 g ...

  2. centOS7升级git版本到2.7.3

    CentOS 自带的git版本太低,需要升级到2.1.2版本以上才能使用gitea. 升级方法: 1.安装所需软件包 yum install curl-devel expat-devel gettex ...

  3. GIT 版本控制常用命令学习汇总

    GIT 版本控制常用命令汇总 git version 查看当前git版本信息 git help 获取全部命令帮助信息 git help <command> 获取指定命令帮助信息 git c ...

  4. Git 与 SVN 命令学习笔记

    一:Git git config --global user.name "you name"   #设置用户名git config --global user.email &quo ...

  5. centos下升级git版本的操作记录

    在使用git pull.git push.git clone的时候,或者在使用jenkins发版的时候,可能会报类似如下的错误: error: The requested URL returned e ...

  6. centos6下升级git版本的操作记录

    编译go_ethereum的时候出现了错误 然后发现是自己的git没有升级成功  因为编译需要高版本的git版本  所以会编译不成功  之后执行 root@uatjenkins01 ~]# git - ...

  7. 转:centos下升级git版本的操作记录

    https://www.cnblogs.com/kevingrace/p/8252517.html 在使用git pull.git push.git clone的时候,或者在使用jenkins发版的时 ...

  8. Git版本恢复命令reset(转载)

    本博文转载自:http://www.tech126.com/git-reset/: 如果看不懂的话,请在git下练习,如果练习后任然有不懂的,可以留言也可以发送邮件到luoquantao@126.co ...

  9. Git 版本恢复命令reset

    reset命令有3中方式: git reset -mixed: 此为默认方式,不带任何参数的git reset, 使用这种方式,项目会回退到某个版本,只保留源码,回退commit和index的信息. ...

随机推荐

  1. mianxiangduixiang

    package com.hanqi; public class mianxiang { public static void main(String[]args) { Cat c1 =new Cat( ...

  2. Python爬虫教程-24-数据提取-BeautifulSoup4(二)

    Python爬虫教程-24-数据提取-BeautifulSoup4(二) 本篇介绍 bs 如何遍历一个文档对象 遍历文档对象 contents:tag 的子节点以列表的方式输出 children:子节 ...

  3. CSS浮动并清除浮动(造成的影响)

    一.浮动 CSS浮动    CSS float浮动的深入研究.详解及拓展(一)    CSS浮动属性Float详解 块级元素独占一行 块级元素,在页面中独占一行,自上而下排列,也就是传说中的流. 可以 ...

  4. Fiddler给网站“优化”

    最近访问某知名网站的速度非常慢,有时候需要2分钟还没完全打开,页面展示了一半就卡住,然后等半天才继续显示下面部分.这种情况已经有几个月了,不知道是他们服务器原因还是我所在网络的问题,但是基本上在其他网 ...

  5. Dubbo框架介绍与安装 Dubbo 注册中心(Zookeeper-3.4.6)

    背景 随着互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,亟需一个治理系统确保架构有条不紊的演进. • 单一应用架构 • 当网站流量很小时, ...

  6. 在IDEA中设置方法自动注释(带参数和返回值)

    第一部分 设置 打开设置面板 新建 在线模板 新建自动添加规则,注意 这里触发的字符 不能随便写 必须为 * Template text 区域 看上去有点乱,但是是为了显示时的对齐,该区域的内容如下( ...

  7. M-AddTwoNumbers-未完成

    /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode ...

  8. simotion连接 V90 1FL6 增量型电机,报警20025 编码器细分设置

    V90 1FL6 增量型电机 The configured fine resolution for Gx_XIST1 (Encoder_N.absEncoder.absResolutionMultip ...

  9. Latex 参考文献引用

    转:http://blog.sina.com.cn/s/blog_4b164557010143tl.html 导入 \usepackage[option]{natbib} 具体的 option 有 r ...

  10. SAP CRM系统订单模型的设计与实现

    SAP成都研究院的一个部门领导让我给他的团队做一个SAP CRM One Order框架的培训,这是我准备的培训内容. 在Jerry之前的文章 基于SAP Kyma的订单编排增强介绍,我表达了自己对S ...