Linux之git用法
文章目录
- 1. 什么是Git?
- 2. 在Linux下安装git
- 3. git 初始化
- 3.1 git工作流程
- 4. git 基础命令
- 4.1 git status
- 4.2 git add
- 4.3 git rm
- 4.4 git commit
- 4.5 git mv
- 4.6 git log
- 4.7 git reset
- 4.8 git branch
- 4.9 git checkout
- 5. Git 标签
1. 什么是Git?
Git 是一个免费的开源软件,分布式版本控制系统旨在处理从小到大的所有内容非常大的项目,速度和效率。
2. 在Linux下安装git
[root@server ~]# yum install -y git # 安装git
[root@server ~]# git config # 查看配置
usage: git config [options]Config file location--global use global config file # 使用全局配置文件--system use system config file # 使用系统级配置文件--local use repository config file # 使用版本库级配置文件
[root@server ~]# git config --global user.name "xiaoge" # 配置git使用用户
[root@server ~]# git config --global user.email "xiaoge@mail.com" # 配置git使用邮箱
[root@server ~]# git config --global color.ui true # 配置语法高亮
3. git 初始化
初始化工作目录,对已经存在的目录进行初始化
[root@server ~]# mkdir git_data # 创建一个目录
[root@server ~]# cd git_data/ # 进入到目录中
[root@server git_data]# init # 初始化
init: required argument missing.
[root@server git_data]# git init # git 初始化
Initialized empty Git repository in /root/git_data/.git/
# 查看工作区状态
[root@server git_data]# git status
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)[root@server git_data]# ll -a
total 4
drwxr-xr-x 3 root root 18 Jul 17 21:35 .
dr-xr-x---. 7 root root 4096 Jul 17 21:34 ..
drwxr-xr-x 7 root root 119 Jul 17 21:36 .git
# 在git_data目录中有隐藏的git文件,说明这是个仓库
3.1 git工作流程
4. git 基础命令
4.1 git status
git status 用于查看仓库的状态;
[root@server git_data]# git status
# On branch master (位于分支 master)
#
# Initial commit(初始提交)
#
nothing to commit (create/copy files and use "git add" to track) (无文件要提交(创建/拷贝文件并使用“git add” 建立跟踪))# 例:
[root@server git_data]# touch a b c
[root@server git_data]# git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# a
# b
# c
nothing added to commit but untracked files present (use "git add" to track)
4.2 git add
git add 的作用是把工作目录中的文件推送到暂存区域;
[root@server git_data]# git add . # ./* 表示把目录中的所有文件都推送到暂存区域
[root@server git_data]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: a
# new file: b
# new file: c
#
4.3 git rm
- 先从暂存区撤回到工作区,然后直接删除文件;
[root@server git_data]# git rm --cached c
rm 'c'
[root@server git_data]# rm -f c
[root@server git_data]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: a
# new file: b
- 直接从暂存区域和工作区域一同删除文件命令;
[root@server git_data]# git rm -f b
rm 'b'
[root@server git_data]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: a
4.4 git commit
git commit 命令用于把暂存区域的文件提交到本地仓库;
git commit 相当于虚拟机的镜像,任何操作都被当做了一次快照,可以恢复到任意一个位置;
[root@server git_data]# git commit -m "commit a " # -m参数:表示后面跟的是提示信息。
[master (root-commit) 6b745dd] commit a1 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 a
[root@server git_data]# git status
# On branch master
nothing to commit, working directory clean # 没有文件提交,干净的工作区
4.5 git mv
git mv 用于修改文件名称
[root@server git_data]# git mv a a.txt # 修改文件名称为a.txt
[root@server git_data]# git status # 查看状态
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# renamed: a -> a.txt
#
[root@server git_data]# git commit -m "rename a a.txt " # 提交到本地仓库
[master 2b9e3bd] rename a a.txt1 file changed, 0 insertions(+), 0 deletions(-)rename a => a.txt (100%)
4.6 git log
git log 用于查看历史的git commit快照操作
[root@server git_data]# git log
commit 2b9e3bd59752448250b8c1ebad87f69053854665
Author: xiaoge <xiaoge@mail.com>
Date: Sat Jul 17 22:18:53 2021 +0800rename a a.txtcommit 6b745dd623da360ce03cf7d0b92924b67232c918
Author: xiaoge <xiaoge@mail.com>
Date: Sat Jul 17 22:06:54 2021 +0800commit a
# 一行简单的显示commit信息
[root@server git_data]# git log --oneline
2b9e3bd rename a a.txt
6b745dd commit a# 显示当前的指针指向哪里
[root@server git_data]# git log --oneline --decorate
2b9e3bd (HEAD, master) rename a a.txt
6b745dd commit a# 显示具体的内容的变化
[root@server git_data]# git log -p
commit 2b9e3bd59752448250b8c1ebad87f69053854665
Author: xiaoge <xiaoge@mail.com>
Date: Sat Jul 17 22:18:53 2021 +0800rename a a.txtdiff --git a/a b/a
deleted file mode 100644
index e69de29..0000000
diff --git a/a.txt b/a.txt
new file mode 100644
index 0000000..e69de29commit 6b745dd623da360ce03cf7d0b92924b67232c918
Author: xiaoge <xiaoge@mail.com>
Date: Sat Jul 17 22:06:54 2021 +0800commit adiff --git a/a b/a
new file mode 100644
index 0000000..e69de29
4.7 git reset
git reset 回滚数据到某一提交点
[root@server git_data]# git reset "某一快照的哈希值"
4.8 git branch
git branch 用于查看分支、创建一个新的分支
# 查看所在分支
[root@server git_data]# git branch
* master # 当前处于主分支
# 创建一个新的分支
[root@server git_data]# git branch new_branch
[root@server git_data]# git branch
* masternew_branch # 新创建的分支
4.9 git checkout
git checkout 用于切换分支
[root@server git_data]# git checkout new_branch
D a
Switched to branch 'new_branch'
[root@server git_data]# git branch master
* new_branch
5. Git 标签
git tag: 可以将某个具体的版本打上一个标签,这样你就不需要记忆复杂的版本号哈希值了,例如你可以使用’git tag v1.0 bbaf6fb5060b4875b18ff9ff637ce118256d6f20’来标记这个被你还原的版本,那么以后你想查看该版本时,就可以使用v1.0标签名,而不是哈希值了;
[root@server git_data]# git tag -a v1.0 -m "first version" # -a指定标签明,-m指定说明信息
[root@server git_data]# git tag
v1.0
[root@server git_data]# git log
commit 6b745dd623da360ce03cf7d0b92924b67232c918
Author: xiaoge <xiaoge@mail.com>
Date: Sat Jul 17 22:06:54 2021 +0800commit a
[root@server git_data]# git tag -a v2.0 6b745dd623da360ce03cf7d0b92924b67232c918 -m "second version "
[root@server git_data]# git tag
v1.0
v2.0# 查看标签信息
[root@server git_data]# git show v1.0
tag v1.0
Tagger: xiaoge <xiaoge@mail.com>
Date: Sat Jul 17 22:44:50 2021 +0800first versioncommit 6b745dd623da360ce03cf7d0b92924b67232c918
Author: xiaoge <xiaoge@mail.com>
Date: Sat Jul 17 22:06:54 2021 +0800commit adiff --git a/a b/a
new file mode 100644
index 0000000..e69de29# 直接还原数据到v2.0
[root@server git_data]# git reset --hard v2.0
HEAD is now at 6b745dd commit a# 删除标签
[root@server git_data]# git tag -d v2.0
Deleted tag 'v2.0' (was 21a8dd8)
[root@server git_data]# git tag
v1.0
Linux之git用法相关推荐
- linux上git克隆命令,Git clone命令用法
git clone是git中常用的命令,其作用是将存储库克隆到新目录中.那么在git中,git clone具体该如何用呢? 更快更轻松的学习Git,请点击Git微课 git clone命令的作用是将存 ...
- 最新GitHub新手使用教程(Linux/Ubuntu Git从安装到使用)——详细图解
说明:该篇博客是博主一字一码编写的,实属不易,请尊重原创,谢谢大家! 一.叙述 1.说明:需要在Windows 安装Git的同学,可以查看该篇博客 https://blog.csdn.net/qq_4 ...
- ❤️开发项目必备技能《Git用法集合》建议收藏❤️
Git用法集合 目录: 文章目录 Git用法集合 目录: 1.什么是版本控制 2.常见的版本控制工具 3.版本控制分类 4.Git与SVN的主要区别 5.软件下载 6.启动Git 7.常用的Linux ...
- git用法从入门到精通
文章目录 前言 一 配置user信息 二 往仓库里添加文件 三 通过git log查看版本演变历史 四 其他git常用的一些命令技巧: 五 git踩坑经历 5.1 git add . 后执行了git ...
- Linux下wine用法
Linux下wine用法 下面是wine的使用方法. 一.要在Linux下运行,wine是必不可少的,所以,请将wine安装到你的系统里. 二.将你的Windows所在的分区加载到某个目录.(本文假定 ...
- linux md5sum 的用法(转)
MD5算法常常被用来验证网络文件传输的完整性,防止文件被人篡改.MD5全称是报文摘要算法(Message-Digest Algorithm 5),此算法对任意长度的信息逐位进行计算,产生一个二进制长度 ...
- linux下git的简单运用
linux下git的简单运用 windows下也有git,是git公司出的bash,基本上模拟了linux下命令行.许多常用的命令和linux下操作一样.也就是说,windows下的git命令操作和l ...
- Linux下Git和GitHub使用方法总结(Ubuntu16.04)
1 Linux下Git和GitHub环境的搭建 第一步: 安装Git,使用命令 "sudo apt-get install git" 第二步: 创建GitHub帐号 第三步: 生成 ...
- Linux export 命令用法
Linux export 命令用法 Linux export 命令用于设置或显示环境变量. 在 shell 中执行程序时,shell 会提供一组环境变量.export 可新增,修改或删除环境变量,供后 ...
最新文章
- 解决:Unknown table engine 'InnoDB'
- 2.linux换源问题
- 在 .NET Core 中如何让 Entity Framework Core 在日志中记录由 LINQ 生成的SQL语句
- P7515-[省选联考 2021A卷]矩阵游戏【差分约束】
- 创建hugo博客_如何创建您的第一个Hugo博客:实用指南
- python支持gui编程_Python GUI编程完整示例
- 作者:周园春(1975-),男,博士,中国科学院计算机网络信息中心研究员、博士生导师。...
- 利用权限禁止QQ的自动升级(QQUpdateCenter)
- 华为畅享20不能升级鸿蒙,华为mate20可以升级鸿蒙os吗-mate20能不能更新鸿蒙系统...
- vue 调用webservice_调用webService的几种方式
- vue05-REST 请求
- 【论文阅读】Automated quantification of white matter lesion in magnetic resonance imaging
- 解决apache启动错误httpd:Could not reliably determine...
- spring学习笔记一(基于xml)
- mysql 中触发器的使用
- 5个最佳网络安全监控工具、 你知道哪些
- JAVA基础编程练习题--50道
- mysql 批量插入(记录帖)
- C盘太小,调整磁盘分区大小
- 计算机专业本科毕业论文周进展,周进展记录.docx