linux - 如何从 'git log' check out Git 中的特定版本?

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

问题 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

最佳答案

您可以使用 git checkout sha-of-commit checkout 提交你已经拥有了。

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

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

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

关于linux - 如何从 'git log' check out Git 中的特定版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6533222/

相关文章:

linux - 找出分区列表和使用百分比

C在linux终端上运行指针错误

mysql - 交互式 ssh 和 mysql 命令的 Bash 脚本

git - 为什么文件被 check out 到索引中显示的先前变更集已修改?

c++ - 如何将ls命令的输出获取到C++中的数组

java - reducer 数量对集群节点数量的依赖性

git - 使用和 merge git 分支的正确方法

git - Beyond Compare git difftool -d 立即关闭,无需等待用户

xml - 在 git 中 merge XML 文件更改

git - 如何知道 .gitignore 的哪一部分实际上负责忽略某些文件?