git学习------>git-rev-parse命令初识
一、准备工作
第一步:在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/
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
第二步:在工作区中创建一个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
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
第三步:在工作区中建立目录 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
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
二、 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
- 1
- 2
- 3
- 4
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
- 1
- 2
- 3
- 4
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/
- 1
- 2
- 3
- 4
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
../../../
- 1
- 2
- 3
- 4
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
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
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
- 1
- 2
- 3
- 4
- 5
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
- 1
- 2
- 3
目前还未建立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
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
git rev-parse –help
git rev-parse命令还有很多种用法,大家可以使用git rev-parse --help
命令打开帮助文档,