如何从"git log"中签出特定版本的Git? [英] How do I check out a particular version in Git from 'git log'?

查看:110
本文介绍了如何从"git log"中签出特定版本的Git?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的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:现在,如何只签出我的第一个版本?

Question 1: Now, how do I check out only my first version?

问题2:同样,当我仅对File1执行git log时,为什么它仅显示第一次提交?

Question 2: Also, when I do git log on only File1, why does it show only the first commit?

 [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

推荐答案

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

You can checkout a commit using git checkout sha-of-commit which you already have.

但是您不能提交任何内容(因为您不在分支中,因此您处于静态提交中).

But you cannot commit anything (as you're not in a branch, you're in a static commit).

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

If you need to commit anything on top of that commit, you need to check it out into a branch using git checkout sha-of-commit -b testing-a-commit.

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

git log <file> only shows commits that affect that file.

这篇关于如何从"git log"中签出特定版本的Git?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆