git rev-parse:将各种引用表示法转换为哈希值等
1,git log显示日志

myroot@myroot:~/linux/linux-5.15.7$ git log
commit ea79e49b21ae8706dfbe5e2f13a766b5b10ac9db (HEAD -> master)
Author: xxxxx(email)
Date:   Sat Mar 19 19:29:29 2022 +0800

linux-5.15.7

2,git status显示修改状态

myroot@myroot:~/linux/linux-5.15.7$ 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:   arch/x86/kernel/setup.c

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

3,git rev-parse --verify --short HEAD:获取最新commit id的简短结果

myroot@myroot:~/linux/linux-5.15.7$ git rev-parse --verify --short HEAD
ea79e49b2

4,git rev-parse --show-cdup:    显示从当前目录后退到工作区的根的深度

myroot@myroot:~/linux/linux-5.15.7$ git rev-parse --show-cdup
结果是空
myroot@myroot:~/linux/linux-5.15.7/include/config$ git rev-parse --show-cdup
../../

5,git rev-parse --verify HEAD:

myroot@myroot:~/linux/linux-5.15.7$ git rev-parse --verify HEAD
ea79e49b21ae8706dfbe5e2f13a766b5b10ac9db

6,git describe:

myroot@myroot:~/linux/linux-5.15.7$ git describe --exact-match
fatal: No names found, cannot describe anything.

myroot@myroot:~/linux/linux-5.15.7$ git describe
fatal: No names found, cannot describe anything.

7,git --no-optional-locks status -uno --porcelain:

myroot@myroot:~/linux/linux-5.15.7$ git --no-optional-locks status -uno --porcelain
 M arch/x86/kernel/setup.c

8,git diff-index:Compare a tree to the working tree or index

myroot@myroot:~/linux/linux-5.15.7$ git diff-index --name-only HEAD
arch/x86/kernel/setup.c

9,git rev-parse --git-dir:显示版本库.git目录所在位置

myroot@myroot:~/linux/linux-5.15.7$ git rev-parse --git-dir
.git

10,git rev-parse --show-toplevel:显示工作区根目录

myroot@myroot:~/linux/linux-5.15.7$ git rev-parse --show-toplevel
/home/myroot/linux/linux-5.15.7

11,git rev-parse --show-prefix:所在目录相对于工作区根目录的相对目录

myroot@myroot:~/linux/linux-5.15.7$ git rev-parse --show-prefix
结果是空
myroot@myroot:~/linux/linux-5.15.7/include/config$ git rev-parse --show-prefix
include/config/

附:linux-5.15.7/scripts/setlocalversion

#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
#
# This scripts adds local version information from the version
# control systems git, mercurial (hg) and subversion (svn).
#
# If something goes wrong, send a mail the kernel build mailinglist
# (see MAINTAINERS) and CC Nico Schottelius
# <nico-linuxsetlocalversion -at- schottelius.org>.
#
#

usage() {
        echo "Usage: $0 [--save-scmversion] [srctree]" >&2
        exit 1
}

scm_only=false
srctree=.
if test "$1" = "--save-scmversion"; then
        scm_only=true
        shift
fi
if test $# -gt 0; then
        srctree=$1
        shift
fi
if test $# -gt 0 -o ! -d "$srctree"; then
        usage
fi

scm_version()
{
        local short
        short=false

cd "$srctree"
        if test -e .scmversion; then
                cat .scmversion
                return
        fi
        if test "$1" = "--short"; then
                short=true
        fi

# Check for git and a git repo.
        if test -z "$(git rev-parse --show-cdup 2>/dev/null)" &&
            head=$(git rev-parse --verify HEAD 2>/dev/null); then

# If we are at a tagged commit (like "v2.6.30-rc6"), we ignore
                # it, because this version is defined in the top level Makefile.
                if [ -z "$(git describe --exact-match 2>/dev/null)" ]; then

# If only the short version is requested, don't bother
                        # running further git commands
                        if $short; then
                                echo "+"
                                return
                        fi
                        # If we are past a tagged commit (like
                        # "v2.6.30-rc5-302-g72357d5"), we pretty print it.
                        if atag="$(git describe 2>/dev/null)"; then
                                echo "$atag" | awk -F- '{printf("-%05d", $(NF-1))}'
                        fi

# Add -g and exactly 12 hex chars.
                        printf '%s%s' -g "$(echo $head | cut -c1-12)"
                fi

# Check for uncommitted changes.
                # This script must avoid any write attempt to the source tree,
                # which might be read-only.
                # You cannot use 'git describe --dirty' because it tries to
                # create .git/index.lock .
                # First, with git-status, but --no-optional-locks is only
                # supported in git >= 2.14, so fall back to git-diff-index if
                # it fails. Note that git-diff-index does not refresh the
                # index, so it may give misleading results. See
                # git-update-index(1), git-diff-index(1), and git-status(1).
                if {
                        git --no-optional-locks status -uno --porcelain 2>/dev/null ||
                        git diff-index --name-only HEAD
                } | read dummy; then
                        printf '%s' -dirty
                fi
        fi
}

collect_files()
{
        local file res=

for file; do
                case "$file" in
                *\~*)
                        continue
                        ;;
                esac
                if test -e "$file"; then
                        res="$res$(cat "$file")"
                fi
        done
        echo "$res"
}

if $scm_only; then
        if test ! -e .scmversion; then
                res=$(scm_version)
                echo "$res" >.scmversion
        fi
        exit
fi

if test -e include/config/auto.conf; then
        . include/config/auto.conf
else
        echo "Error: kernelrelease not valid - run 'make prepare' to update it" >&2
        exit 1
fi

# localversion* files in the build and source directory
res="$(collect_files localversion*)"
if test ! "$srctree" -ef .; then
        res="$res$(collect_files "$srctree"/localversion*)"
fi

# CONFIG_LOCALVERSION and LOCALVERSION (if set)
res="${res}${CONFIG_LOCALVERSION}${LOCALVERSION}"

# scm version string if not at a tagged commit
if test "$CONFIG_LOCALVERSION_AUTO" = "y"; then
        # full scm version string
        res="$res$(scm_version)"
elif [ "${LOCALVERSION+set}" != "set" ]; then
        # If the variable LOCALVERSION is not set, append a plus
        # sign if the repository is not in a clean annotated or
        # signed tagged state (as git describe only looks at signed
        # or annotated tags - git tag -a/-s).
        #
        # If the variable LOCALVERSION is set (including being set
        # to an empty string), we don't want to append a plus sign.
        scm=$(scm_version --short)
        res="$res${scm:++}"
fi

echo "$res"

git rev-parse之操作笔记相关推荐

  1. [Git]git的一些常用操作笔记

    回滚到某次历史提交: git log:查看分支提交历史,确认需要回退的版本 git reset --hard commit_id:进行版本回退 git push --force origin:推送至远 ...

  2. Node.js Git Server搭建及Git常用操作笔记

    Node.js Git Server搭建及Git常用操作笔记 安装Git工具即可在本地进行Git仓库的管理,如果要实现远程仓库则需要搭建Git Server.通过Node.js搭建Git Server ...

  3. GIT Windows服务端搭建笔记

    GIT Windows服务端搭建笔记 所需软件: GIT服务端: Bonobo Git Server,下载最新版 https://bonobogitserver.com/ 一:配置服务端(基于Wind ...

  4. json.js+ jquery 操作笔记

    json.js+ jquery 操作笔记 json.js下载地址: http://www.json.org/js.html 我初学JSON,按照官方说明,在json2.js中有parse和string ...

  5. Ubuntu科学操作笔记---kalrry

    Ubuntu科学操作笔记---kalrry 前言 一.分区 二.换源 三.安装软件 二.更换app商店 二.雷鸟邮箱改中文语言 二.安装deepin的wine环境 前言 Win配置记录 Mac配置记录 ...

  6. 关于 Linux中Git等知识的一些笔记

    写在前面 嗯,Git一般都用平台上的,自己用Githup,Gitee,公司用的Gitlab,服务端的没搞过,基本用的都是客户端. 之前实习分了一个项目做组长,所以自己在阿里云上面搭了SVN的服务端,折 ...

  7. Parse算法学习笔记

    Parse算法学习笔记 Parse算法是一种自底向上的语法分析算法,其主要应用于编译器中的语法分析阶段.相比于其他语法分析算法,Parse算法具有简单.高效的特点.本篇文章将详细介绍Parse算法的原 ...

  8. Git单人本地仓库操作

    Git单人本地仓库操作 以下为演示Git单人本地仓库操作 1.安装git sudo apt-get install git密码:chuanzhi 2.查看git安装结果 git 3.创建项目 在桌面创 ...

  9. Spark+hadoop+mllib及相关概念与操作笔记

    Spark+hadoop+mllib及相关概念与操作笔记 作者: lw 版本: 0.1 时间: 2016-07-18 1.调研相关注意事项 a) 理解调研 调研的意义在于了解当前情况,挖掘潜在的问题, ...

  10. Altium designer 操作笔记

    Altium designer 操作笔记 目录: 1.查找元器件 2.设置走线的最小间距 3.检查pcb走线等违反规则的错误 4.去除选中赋铜 5.查找相似对象 6.sch原理图文件转pcb文件 7. ...

最新文章

  1. GAN的基本原理与入门应用!
  2. 娓娓道来!那些BERT模型压缩方法
  3. 我在神策做研发 | 成长中的成都研发中心
  4. 用scikit-learn和pandas学习线性回归
  5. Microsoft AI - Custom Vision in C#
  6. 【RS码1】系统RS码编码原理及MATLAB实现(不使用MATLAB库函数)
  7. HM发卡系统 十分好看的ui
  8. 基于Qt的P2P局域网聊天及文件传送软件设计
  9. 贷中风控调额方法与策略详解
  10. 几步教你用 Python 制作一个 RPA 机器人!
  11. 3-6 字符和字符串处理
  12. 明翰恶意软件分析笔记V0.1(持续更新)
  13. 微信公众平台开发问答
  14. mac sierra mysql_Mac High Sierra一步搞定Mysql安装
  15. 区块链钱包—BTC Java版离线签名交易
  16. typora配置好smms后还是typora上传图片失败:image load failed。
  17. 达奇机器人编程学院_Wonder Workshop Dash Robot 达奇STEM编程机器人 中英文双语版
  18. 速卖通获得aliexpress商品详情 API
  19. Flutter集成个推推送-安卓原生篇
  20. Cobalt Strike(三)DNS beacon 的使用与原理

热门文章

  1. 【2022最新Java面试宝典】—— Tomcat面试题(15道含答案)
  2. webstorm安装使用教程
  3. 改变mysql的数据编码格式_修改数据库编码格式(转)
  4. pytorch 中 squeeze 和unsqueeze函数
  5. uni-app踩坑之旅
  6. html5 智能表单
  7. CentOS6.5 安装Sphinx 配置MySQL数据源
  8. scrapy splash 实现下滑加载
  9. 网站/页面即时聊天客服功能
  10. 输入url,一次请求流程