2010-03-27 82 views
0
git init 
echo 'I am foo' > foo.txt 
git add foo.txt # this woould create a git commit object 
echo ' I am foo2' > foo.txt 
git add foo.txt # this would create another git commit object 
git commit -m 'doe' # this would create two git 
        # objects: one commit object and one tree object 

如何获得所有4个提交列表SHA1_HASH?所有提交列表SHA1_HASH

cd .git/objects 
ls 
(master)$ ls -al 
total 0 
drwxr-xr-x 8 nsingh staff 272 Mar 27 16:44 . 
drwxr-xr-x 13 nsingh staff 442 Mar 27 16:44 .. 
drwxr-xr-x 3 nsingh staff 102 Mar 27 16:44 37 
drwxr-xr-x 3 nsingh staff 102 Mar 27 16:43 a2 
drwxr-xr-x 3 nsingh staff 102 Mar 27 16:44 e1 
drwxr-xr-x 3 nsingh staff 102 Mar 27 16:42 e6 
drwxr-xr-x 2 nsingh staff 68 Mar 27 16:42 info 
drwxr-xr-x 2 nsingh staff 68 Mar 27 16:42 pack 

我可以通过查看文件在这里找到所有4个提交的列表,但必须有更好的方法。

+0

你对创建四个提交对象也有点错误。所有的'git add'都会检查事物到索引中。当您运行'git commit'时,您只创建了一个提交。你几乎可以肯定不需要知道该提交树的SHA1是什么,但是如果你想知道,你可以使用'git log --pretty =%T'来看看它。 – Cascabel 2010-03-27 21:21:20

+0

通过执行所有这些操作创建的对象是:提交(来自git commit),树(提交的树)和blob(foo.txt的内容)。第一个回声/添加对没有持续的影响,因为你用下一对覆盖了它。 – Cascabel 2010-03-27 21:22:53

+1

要了解有关内部的更多信息,请尝试使用git社区书籍:http://book.git-scm.com/1_the_git_object_model.html或pro git:ttp://progit.org/book/ch9-2.html(在许多其他版本中) – Cascabel 2010-03-27 21:24:33

回答

2

尝试git log --pretty=oneline

2

git log --format=format:%H只会打印出提交散列,每行一个。看看man git-logpretty formats section有关格式选项的更多信息。 --pretty=oneline建议是类似的,但也会为您提供提交消息以及哈希。

+0

在当前版本的git中,你不需要额外的前缀 - 你可以做'git log --pretty =%H'。 – Cascabel 2010-03-27 21:17:05

+3

或使用'git rev-list' – 2010-03-27 22:22:10

0

如果您只想要缩写SHA 1,请尝试git log --abbrev-commit --pretty=oneline

相关问题