一、准备工作
第一步:在d盘git test目录下,新建工作区根目录demo,进入该目录后,执行git init创建版本库。
DH207891+OuyangPeng@DH207891 MINGW32 /d/git test
$ mkdir demo
DH207891+OuyangPeng@DH207891 MINGW32 /d/git test
$ cd demo/
DH207891+OuyangPeng@DH207891 MINGW32 /d/git test/demo
$ git init
Initialized empty Git repository in D:/git test/demo/.git/
第二步:在工作区中创建一个welcom.txt文件,内容就是“hello .”,然后将该文件加入到git版本库中。
DH207891+OuyangPeng@DH207891 MINGW32 /d/git test/demo (master)
$ echo "hello ." > welcome.txt
DH207891+OuyangPeng@DH207891 MINGW32 /d/git test/demo (master)
$ ll
total 1
-rw-r--r-- 1 DH207891+OuyangPeng 197609 8 6月 13 08:45 welcome.txt
DH207891+OuyangPeng@DH207891 MINGW32 /d/git test/demo (master)
$ git add welcome.txt
warning: LF will be replaced by CRLF in welcome.txt.
The file will have its original line endings in your working directory.
DH207891+OuyangPeng@DH207891 MINGW32 /d/git test/demo (master)
$ git st
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: welcome.txt
DH207891+OuyangPeng@DH207891 MINGW32 /d/git test/demo (master)
$ git ci -m "Initialized"
[master (root-commit) 89c9fa6] Initialized
1 file changed, 1 insertion(+)
create mode 100644 welcome.txt
DH207891+OuyangPeng@DH207891 MINGW32 /d/git test/demo (master)
$ git log
commit 89c9fa626e7d56c686e904ba34b8e21e9aaf43d8
Author: ouyangpeng <oypcz@foxmail.com>
Date: Tue Jun 13 08:46:17 2017 +0800
Initialized
第三步:在工作区中建立目录 a/b/c,进入到该目录中。
DH207891+OuyangPeng@DH207891 MINGW32 /d/git test/demo (master)
$ mkdir -p a/b/c
DH207891+OuyangPeng@DH207891 MINGW32 /d/git test/demo (master)
$ cd a/b/c/
DH207891+OuyangPeng@DH207891 MINGW32 /d/git test/demo/a/b/c (master)
$ pwd
/d/git test/demo/a/b/c
二、 git rev-parse 命令
git rev-parse –git-dir
显示版本库.git命令所在的位置,执行命令 git rev-parse --git-dir
DH207891+OuyangPeng@DH207891 MINGW32 /d/git test/demo/a/b/c (master)
$ git rev-parse --git-dir
D:/git test/demo/.git
git rev-parse –show-toplevel
显示工作区根目录,执行命令 git rev-parse --show-toplevel
DH207891+OuyangPeng@DH207891 MINGW32 /d/git test/demo/a/b/c (master)
$ git rev-parse --show-toplevel
D:/git test/demo
git rev-parse –show-prefix
显示相对于工作区根目录的相对路径,执行命令 git rev-parse --show-prefix
DH207891+OuyangPeng@DH207891 MINGW32 /d/git test/demo/a/b/c (master)
$ git rev-parse --show-prefix
a/b/c/
git rev-parse –show-cdup
显示从当前目录(cd)后退(up)到工作区的根目录的深度,执行命令 git rev-parse --show-cdup
DH207891+OuyangPeng@DH207891 MINGW32 /d/git test/demo/a/b/c (master)
$ git rev-parse --show-cdup
../../../
git rev-parse –local-env-vars
显示git环境变量列表的本地库,只列出变量的名称,而不是它们的值。执行命令git rev-parse --local-env-vars
DH207891+OuyangPeng@DH207891 MINGW32 /d/git test/demo/a/b/c (master)
$ git rev-parse --local-env-vars
GIT_ALTERNATE_OBJECT_DIRECTORIES
GIT_CONFIG
GIT_CONFIG_PARAMETERS
GIT_OBJECT_DIRECTORY
GIT_DIR
GIT_WORK_TREE
GIT_IMPLICIT_WORK_TREE
GIT_GRAFT_FILE
GIT_INDEX_FILE
GIT_NO_REPLACE_OBJECTS
GIT_REPLACE_REF_BASE
GIT_PREFIX
GIT_INTERNAL_SUPER_PREFIX
GIT_SHALLOW_FILE
GIT_COMMON_DIR
git rev-parse –git-common-dir
如果GIT_COMMON_DIR变量定义了则展示GIT_COMMON_DIR变量的值,不然则展示GIT_DIR变量的值
DH207891+OuyangPeng@DH207891 MINGW32 /d/git test/demo/a/b/c (master)
$ git rev-parse --git-common-dir
a/b/c/.git
git rev-parse –symbolic –branches
显示分支,执行命令 git rev-parse --symbolic --branches
目前只有master一个分支,所以只显示master。
git rev-parse –symbolic –tags
显示里程碑,执行命令 git rev-parse --symbolic --tags
DH207891+OuyangPeng@DH207891 MINGW32 /d/git test/demo/a/b/c (master)
$ git rev-parse --symbolic --tags
目前还未建立TAG,所以没有值显示。
git rev-parse HEAD
显示HEAD提交的SHA1值,执行命令git rev-parse HEAD
,如下所示,先执行git log
命令查看提交记录,再执行命令git rev-parse HEAD
DH207891+OuyangPeng@DH207891 MINGW32 /d/git test/demo/a/b/c (master)
$ git log
commit 89c9fa626e7d56c686e904ba34b8e21e9aaf43d8
Author: ouyangpeng <oypcz@foxmail.com>
Date: Tue Jun 13 08:46:17 2017 +0800
Initialized
DH207891+OuyangPeng@DH207891 MINGW32 /d/git test/demo/a/b/c (master)
$ git rev-parse HEAD
89c9fa626e7d56c686e904ba34b8e21e9aaf43d8
git rev-parse –help
git rev-parse命令还有很多种用法,大家可以使用git rev-parse --help
命令打开帮助文档,
或者打开 在线文档 https://www.kernel.org/pub/software/scm/git/docs/git-rev-parse.html
参考链接
https://www.kernel.org/pub/software/scm/git/docs/git-rev-parse.html
http://docs.oracle.com/cd/E56344_01/html/E54075/git-rev-parse-1.html
http://blog.chinaunix.net/uid-27714502-id-3435772.html
http://blog.csdn.net/agul_/article/details/7842885
作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!
转载请保留原文地址:http://blog.csdn.net/ouyang_peng/article/details/72903221如果本文对您有所帮助,欢迎您扫码下图所示的支付宝和微信支付二维码对本文进行打赏。