2010-03-27 57 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