Git工具使用
-
GIT(分布式版本控制系统)
1.安装git
[root@controller ~]# rpm -aq git
git-1.8.3.1-12.el7_4.x86_64 //可以看到该系统上已经安装了git
如果未安装则运行以下命令即可:
yum install -y git
2.版本库创建
创建一个版本库非常简单,首先,选择一个合适的地方,创建一个空目录:
[root@controller ~]# mkdir git_db
[root@controller ~]# cd git_db/
[root@controller git_db]# git init
Initialized empty Git repository in /root/git_db/.git/
[root@controller git_db]# ls -a
. .. .git
git init命令生成一个版本库,我们可以看到提示”Initialized empty Git repository“ 是说这是一个空的仓库,可以通过ls -a命令查看隐藏的目录。
接下来我们在当前目录(/root/git_db/)下编写一个文档,记住一定要到git init 生成版本库的目录下创建,不然git无法识别。
[root@controller git_db]# cat first_file.txt
hello git
这是第一个版本
下面将一个文件放到Git仓库只需要两步。
第一步:用命令git add告诉Git,把文件添加到仓库:
[root@controller git_db]# git add first_file.txt
You have new mail in /var/spool/mail/root
[root@controller git_db]#
没有输入其他内容说明添加成功。
第二步:用命令git commit告诉Git提交说明,把文件提交到仓库:(这一步是必须的)
[root@controller git_db]# git commit -m "this is my fisrt git file" *** Please tell me who you are. Run git config --global user.email "you@example.com"
git config --global user.name "Your Name" to set your account's default identity.
Omit --global to set the identity only in this repository. fatal: unable to auto-detect email address (got 'root@controller.(none)')
You have new mail in /var/spool/mail/root
我们可以看到提示出错无法提交,原因是没有设置名字和邮件地址Git仓库无法发送,我们需要做的是按照Run下提示的代码运行即可。
[root@controller git_db]# git config --global user.email "xxxx@qq.com"
[root@controller git_db]# git config --global user.name "alai" [root@controller git_db]# git commit -m "this is my fisrt git file"
[master (root-commit) a86e828] this is my fisrt git file
1 file changed, 2 insertions(+)
create mode 100644 first_file.txt
再次运行commit 命令可以看到已经成功上传Git仓库。
3.代码回滚设置
修改文档
[root@controller git_db]# cat first_file.txt
hello git
这是第二个版本
现在,运行git status命令看看结果:
[root@controller git_db]# 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: first_file.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
虽然Git告诉我们first_file.txt被修改了,但是不清楚修改了什么内容。需要用git diff这个命令看看:
[root@controller git_db]# git diff first_file.txt
diff --git a/first_file.txt b/first_file.txt
index 680655c..407ee40 100644
--- a/first_file.txt
+++ b/first_file.txt
@@ -1,2 +1,2 @@
hello git
-这是第一个版本
+这是第二个版本
输出中+号显示的就是修改或新增的内容,-号显示的就是去掉或被修改的内容
我们再次提交到Git仓库上:
[root@controller git_db]# git add . //.表示当前目录下所有改变的文档
You have new mail in /var/spool/mail/root
[root@controller git_db]# git commit -m "changes"
[master 25d561b] changes
1 file changed, 1 insertion(+), 1 deletion(-) [root@controller git_db]# git status
# On branch master
nothing to commit, working directory clean
在Git中,我们用git log命令查看历史记录:
[root@controller git_db]# git log
commit 25d561b0a53a764acf15b06a53ffab34598d455e
Author: alai <1259525@qq.com>
Date: Sun Feb 11 16:41:56 2018 +0800 changes commit a86e82810819202830f618440fbf4acaf3114498
Author: alai <1259525@qq.com>
Date: Sun Feb 11 16:28:56 2018 +0800 this is my fisrt git file
加上--pretty=oneline参数简化输出:
[root@controller git_db]# git log --pretty=oneline
25d561b0a53a764acf15b06a53ffab34598d455e changes
a86e82810819202830f618440fbf4acaf3114498 this is my fisrt git file
第一列是commit id(版本号),第二列是commit。
开始回滚
首先,Git必须知道当前版本是哪个版本,在Git中,用HEAD表示当前版本,上一个版本就是HEAD^,上上一个版本就是HEAD^^,当然往上100个版本写100个^比较容易数不过来,所以写成HEAD~100。使用git reset --hard命令:
#查看当前版本为25d。。
[root@controller git_db]# git reset --hard HEAD
HEAD is now at 25d561b changes
You have new mail in /var/spool/mail/root
[root@controller git_db]# cat first_file.txt
hello git
这是第二个版本 #退回上一个版本
[root@controller git_db]# git reset --hard HEAD^
HEAD is now at a86e828 this is my fisrt git file
[root@controller git_db]# cat first_file.txt
hello git
这是第一个版本
这是我们又想回到最新的那个版本,你通过命令git log --pretty=oneline查看已经没有了,这时候该怎么办呢,翻日志找到该版本的commit id 命令如下:
[root@controller git_db]# git reset --hard 25d561 //commit id不必写全 git会自动查询
HEAD is now at 25d561b changes
[root@controller git_db]# cat first_file.txt
hello git
这是第二个版本
Git工具使用的更多相关文章
- 【转】第 02 天:在 Windows 平台必裝的三套 Git 工具
原文网址:https://github.com/doggy8088/Learn-Git-in-30-days/blob/master/docs/02%20%E5%9C%A8%20Windows%20% ...
- windows中使用Git工具连接GitHub(配置篇)
Git在源码管理领域目前占很大的比重了,而且开源的项目很多都转到GitHub上面了.例如:jQuery, reddit, Sparkle, curl, Ruby on Rails, node.js, ...
- Git详解之六 Git工具(转)
Git 工具 现在,你已经学习了管理或者维护 Git 仓库,实现代码控制所需的大多数日常命令和工作流程.你已经完成了跟踪和提交文件的基本任务,并且发挥了暂存区和轻量级的特性分支及合并的威力. 接下来你 ...
- Git详解之六:Git工具
Git 工具 现在,你已经学习了管理或者维护 Git 仓库,实现代码控制所需的大多数日常命令和工作流程.你已经完成了跟踪和提交文件的基本任务,并且发挥了暂存区和轻量级的特性分支及合并的威力.(伯乐在线 ...
- 使用git工具将项目上传到github
注册github账号 https://github.com/ 安装git工具: https://git-for-windows.github.io/ 上面的准备工作完成后,现在开始操作. 一.进入gi ...
- Git工具的使用教程
Git 是一种版本控制工具,也叫作版本管理软件(分布式管理软件).这里介绍Git的基本使用步骤,关于 Git 更详细的介绍,读者可以参考其官方网站提供的文档. 1 安装Git 在Ubuntu系统中安 ...
- 使用git工具快速push项目到github(精简)
Dear Weber ,相信有很多刚开始接触前端的程序猿,在刚接触到git工具传项目到github上时会遇到一些问题,那么下面的话呢,我就整理一下一个大致的思路提供给大家参考: 工具:git (自行下 ...
- 代码管理工具:使用github和git工具管理自己的代码
一.git工具和账户创建 1.1 安装 Git 是 Linus Torvalds 最近实现的源代码管理软件."Git 是一个快速.可扩展的分布式版本控制系统,它具有极为丰富的命令集,对内部系 ...
- 使用git工具上传自己的程序到github上
一:前期准备 可以运行的项目 github账号 git工具 二:开始操作 1.创建个人github仓库 写自己项目的名字,描述,权限,README 2.新建结束后会进入如下界面 3.复制仓库地址 4. ...
随机推荐
- Python+Selenium学习--自动化测试模型
前言 一个自动化测试框架就是一个集成体系,在这一体系中包含测试功能的函数库.测试数据源.测试对象识别标准,以及种可重用的模块.自动化测试框架在发展的过程中经历了几个阶段,模块驱动测试.数据驱动测试.对 ...
- 正则RegExp的懒惰性和贪婪性; 分组捕获;
1.正则的懒惰性??? 每次在它的方法exec中捕获的时候,只捕获第一次匹配的内容,而不往下捕获,我们把这种情况称为正则的懒惰性 且每一次捕获的位置都是从索引0开始 正则的实例对象上有一个lastin ...
- java【基础】多态
new 接口就会发生很有意思的现象 public class InerClassDemo { public static void main(String[] args) { // TODO Auto ...
- mysql开启调试日志general_log开启跟踪日志
general_log = 1 general_log_file = /tmp/umail_mysql.log 有时候,不清楚程序执行了什么sql语句,但是又要排除错误,找不到原因的情况下, 可以在m ...
- python基础之Day7part2 史上最清晰字符编码理解
二.字符编码 基础知识: 文本编辑器存取文件原理与py执行原理异同: 存/写:进入文本编辑器 写内容 保存后 内存数据刷到硬盘 取/读:进入文本编辑器 找到内容 从硬盘读到内存 notepad把文件内 ...
- mvc输出json时报HTTP Status 406错误
1.mvc输出json时报HTTP Status 406错误 错误纠结了2天时间,今天总与整对了,少jackson-databind引用 对于Spring 4.1.x 和以上, jackson-dat ...
- SPOJ - AMR11B
题目链接:https://www.spoj.com/problems/AMR11B/en/ 题目大意就是要你求图形覆盖的格点数,标记每个图形里的未标记格点(包括边界),总标记数就是覆盖的总格点数. # ...
- Java多线程系列4 线程交互(wait和notify方法)
wait()/ notify()/ notifyAll() 任何Object对象都可以作为这三个方法的主调,但是不推荐线程对象调用这些方法. 1使用wait().notify()和notifyAll( ...
- MSSQL语句学习(查询表的总记录数)
如何高效查询表的总记录数(通用方法) SELECT COUNT(1) ROWS FROM product 野路子1:利用系统自带的存储过程SP_SPACEUSED,详细的使用方式推荐谷哥或度娘, EX ...
- [C#.net]ListBox对Item进行重绘,设置背景色和前景色
别的不多说了,上代码,直接看 首先设置这行,或者属性窗口设置,这样才可以启动手动绘制,参数有三个 Normal: 自动绘制 OwnerDrawFixed:手动绘制,但间距相同 OwnerDrawVar ...