2011-06-30 95 views
10

我的git的日誌顯示的東西如:如何從git log中檢出git中的特定版本?

enter code here 
[git_trial]$ git log 
commit 4c5bc66ae50780cf8dcaf032da98422aea6e2cf7 
Author: king <[email protected]> 
Date: Thu Jun 30 15:09:55 2011 +0530 


This is third commit 

commit 8072be67ddd310bc200cab0dccb8bcb2ec4f922c 

Author: king <[email protected]> 

Date: Thu Jun 30 14:17:27 2011 +0530 

This is the second commit 

commit 3ba6ce43d500b12f64368b2c27f35211cf189b68 

Author: king <[email protected]> 

Date: Thu Jun 30 14:00:01 2011 +0530 


This is the first git commit for file1 

問題1)現在怎麼只檢出我的第一個版本? 問題2)另外當我這樣做,git僅登錄File1,爲什麼它只顯示第一次提交?

[git_trial]$ git checkout 3ba6ce43d500b12f64368b2c27f35211cf189b68 
Note: moving to "3ba6ce43d500b12f64368b2c27f35211cf189b68" which isn't a local branch 
If you want to create a new branch from this checkout, you may do so 
(now or later) by using -b with the checkout command again. Example: 

    git checkout -b <new_branch_name> 


    [git_trial]$ git log File1 

    commit 3ba6ce43d500b12f64368b2c27f35211cf189b68 

    Author: king <[email protected]> 
    Date: Thu Jun 30 14:00:01 2011 +0530 

    This is the first git commit for file1 

回答

28

您可以使用您已有的git checkout sha-of-commit簽出提交。

但是你不能提交任何東西(因爲你不在分支中,你在靜態提交中)。

如果您需要在該提交之上提交任何內容,則需要使用git checkout sha-of-commit -b testing-a-commit將其簽出到分支中。

git log <file>只顯示影響該文件的提交。

+0

對不起,遲到的響應..網絡太慢了。所以你的意思是,如果我創建一個分支,然後做我的第一次和連續的提交,那麼我可以簽出任何特定的版本? – kingsmasher1

+0

什麼是提交sha? – kingsmasher1

+0

@ kingshasher1,sha = SHA1散列,如'3ba6ce43d500b12f64368b2c27f35211cf189b68'。 – Dogbert