如何从“git log”中检出特定版本的Git代码?

29

我的 git log 显示如下:

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


This is third commit

commit 8072be67ddd310bc200cab0dccb8bcb2ec4f922c

Author: king <king@king.ap.com>

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

This is the second commit

commit 3ba6ce43d500b12f64368b2c27f35211cf189b68

Author: king <king@king.ap.com>

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


This is the first git commit for file1

问题1:现在,我如何仅检出我的第一个版本?

问题2:另外,当我只对File1执行git log时,为什么它只显示第一个提交?

 [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 <king@king.ap.com>
  Date:   Thu Jun 30 14:00:01 2011 +0530

  This is the first git commit for file1
1个回答

67

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

但是您不能提交任何内容(因为您不在分支中,而是在静态提交中)。

如果您需要在该提交上提交任何内容,则需要使用git checkout sha-of-commit -b testing-a-commit将其检出到分支中。

git log <file>仅显示影响该文件的提交记录。


抱歉回复晚了,这里的.net速度太慢了。你的意思是,如果我创建一个分支,然后进行第一次和随后的提交,那么我就可以检出任何特定版本? - RajSanpui
@kingshasher1,sha = SHA1哈希值,例如3ba6ce43d500b12f64368b2c27f35211cf189b68 - Dogbert
你在这里究竟想做什么?为什么要检查一个提交?只是为了阅读,还是要在其基础上提交一些东西? - Dogbert
2
如果你只想阅读源代码,git checkout <sha> 就可以了。 - Dogbert

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接