Git常用命令show和status和config

Git常用命令show和status和config

1、show

显示各种类型的对象。

1.1 显示commit

# 显示某次提交的元数据和内容变化
# commit可以是全部的字符串,也可以前几个字符串
$ git show commit
$ git show b9709d6e59
commit b9709d6e59125cc6d6de086527984cf1cab37c0f (HEAD -> branch_a, origin/branch_a)
Author: zsx242030 <2420309401@qq.com>
Date:   Thu May 18 20:36:54 2023 +0800

    branch_a | update a.txt | add new.txt

diff --git a/a.txt b/a.txt
index e69de29..dd18a66 100644
--- a/a.txt
+++ b/a.txt
@@ -0,0 +1 @@
+branch_a
diff --git a/new.txt b/new.txt
new file mode 100644
index 0000000..1a3f285
--- /dev/null
+++ b/new.txt
@@ -0,0 +1 @@
+branch_a_new
# 显示某次提交发生变化的文件
$ git show --name-only commit
$ git show --name-only b9709d6e59
commit b9709d6e59125cc6d6de086527984cf1cab37c0f (HEAD -> branch_a, origin/branch_a)
Author: zsx242030 <2420309401@qq.com>
Date:   Thu May 18 20:36:54 2023 +0800

    branch_a | update a.txt | add new.txt

a.txt
new.txt
# 显示某次提交时,某个文件的内容
$ git show commit:filename
$ git show b9709d6e59:a.txt
branch_a

1.2 显示tag

# 查看tag信息
$ git show tag_name
# 显示v2.0的日志及详细内容
$ git show v2.0

1.3 显示HEAD提交日志

HEAD+数字:表示当前提交的父提交,具体是第几个父提交通过+数字指定,HEAD1第一个父提交,该语法只

能用于合并(merge)的提交记录,因为一个通过合并产生的commit对象才有多个父提交。

HEAD~+数字:(等同于HEAD^,注意没有加数字)。表示当前提交的上一个提交,具体是第几个提交通过+数字指

定,HEAD~1第一个提交。

HEAD^主要是控制merge之后回退的方向。

HEAD~主要是回退的步数。

# 显示HEAD提交日志
$ git show HEAD
commit b9709d6e59125cc6d6de086527984cf1cab37c0f (HEAD -> branch_a, origin/branch_a)
Author: zsx242030 <2420309401@qq.com>
Date:   Thu May 18 20:36:54 2023 +0800

    branch_a | update a.txt | add new.txt
# 显示最新一次提交的第一个父提交
$ git show HEAD^1

# 显示最新一次提交的第二个父提交
$ git show HEAD^2
# 第一父提交的第一父提交
# ^^为上两个版本
$ git show HEAD^^
# 显示最新一次提交的上两个提交
# n为几就是第几个提交
$ git show HEAD~2
# HEAD^和HEAD~结合使用
# 第3个提交的第二个父提交
$ git show HEAD~3^2
# 可使用@{n}来引用git reflog中输出的记录,其中HEAD@{n}若为提交记录,则输出提交记录信息
# 若非提交记录,则输出所在的分支的最近一次提交记录
# 注意reflog引用日志只存在本地仓库,记录仓库内的操作信息,新克隆的仓库引用日志为空
$ git show HEAD@{2}
# 显示master分支昨天的状态
$ git show master@{yesterday}
$ git show -s --pretty=raw b9709d6e59
commit b9709d6e59125cc6d6de086527984cf1cab37c0f
tree a7685436a8d1fb4c70f0d4fa9c30d99efecfd597
parent 105370e6eef7f0a4620139d436e8f1f0e8aa7a7d
author zsx242030 <2420309401@qq.com> 1684413414 +0800
committer zsx242030 <2420309401@qq.com> 1684413414 +0800

    branch_a | update a.txt | add new.txt

2、status

显示工作目录和暂存区的状态。

# 显示有变更的文件
# 显示所有需要提交的文件
$ git status
# 获得简短的状态输出
$ git status -s

3、config

git config 用于获取并设置存储库或全局选项。

git 的设置文件为 .gitconfig,它可以在用户主目录下(全局配置),也可以在项目目录下(项目配置)。

3.1 配置 Git

# 设置提交代码时的用户信息(用户名和电子邮件)
# local只对当前仓库有效
# global所有仓库有效
# system对系统所有用户有效
$ git config [--global|--local|--system] user.name "name"
$ git config [--global|--local|--system] user.email "email address"
# 配置全局用户
$ git config --global user.name "用户名"
$ git config --global user.email "用户邮箱"
# 例如
$ git config --local user.name "zsx242030"
$ git config --local user.email "2420309401@qq.com"
# 设置文本编辑器
$ git config --global core.editor emacs
# 差异分析工具
# 在解决合并冲突时使用哪种差异分析工具
# kdiff3,tkdiff,meld,xxdiff,emerge,vimdiff,gvimdiff,ecmerge,opendiff
$ git config --global merge.tool vimdiff
# 配置git status等命令自动着色
$ git config --global color.ui true                         
$ git config --global color.status auto
$ git config --global color.diff auto
$ git config --global color.branch auto
$ git config --global color.interactive auto
# 显示历史记录时,每个提交的信息只显示一行
$ git config format.pretty oneline
# 配置别名
$ git config --global alias.co checkout
$ git config --global alias.ss status
$ git config --global alias.cm commit
$ git config --global alias.br branch
$ git config --global alias.rg reflog
# 这里只是美化log的输出,实际使用时可以在git lg后面加命令参数
# 如git lg -10显示最近10条提交
$ git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
# 编辑Git配置文件
# 会出现一个编辑界面,自己填写相应的信息
$ git config -e --global|--local|--system
# 清除配置
# local只对当前仓库有效
# global所有仓库有效
# system对系统所有用户有效
$ git config --unset --local [user.name|user.email]
$ git config --unset --global [user.name|user.email]
$ git config --unset --system [user.name|user.email]
# 例如
$ git config --unset --local user.name
$ git config --unset --local user.email
$ git config --unset --global alias.lg

config 的增删改查操作如下:

# 查
git config --global --list

git config --global user.name
git config --global user.email

#  增
git config  --global --add user.name xxx
git config  --global --add user.email xxx

# 删
git config  --global --unset user.name xxx
git config  --global --unset user.email xxx

# 改
git config --global user.name xxx
git config --global user.email xxx

3.2 查看 Git 信息

# 显示当前的Git配置
# 不加参数默认是system
# local只对当前仓库有效
# global所有仓库有效
# system对系统所有用户有效
$ git config --list [--global|--local|--system]
# 查看系统配置
$ git config --list
$ git config --list --local
$ git config --list --global
$ git config --list --system
# 查看用户配置
$ cat ~/.gitconfig
# 查看当前项目的git配置
$ cat .git/config
# 查看当前HEAD指向
$ cat .git/HEAD
ref: refs/heads/master
# 查看所有git命令
$ git --help -a
# 查看某个配置
$ git config user.name
zsx242030
# 编辑git配置文件
# 针对当前仓库
$ git config -e

# 针对系统上所有仓库
$ git config -e --global
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值