Linux 如何从“git log”中检出 Git 中的特定版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6533222/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I check out a particular version in Git from 'git log'?
提问by kingsmasher1
My git log
is showing something as:
我git log
的显示如下:
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
Question 1: Now, how do I check out only my first version?
问题 1:现在,我如何只签出我的第一个版本?
Question 2: Also, when I do git log
on only File1, why does it show only the first commit?
问题 2:另外,当我git log
只在 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
采纳答案by Dogbert
You can checkout a commit using git checkout sha-of-commit
which you already have.
您可以使用git checkout sha-of-commit
已有的提交来签出。
But you cannot commit anything (as you're not in a branch, you're in a static 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 checkout sha-of-commit -b testing-a-commit
.
git log <file>
only shows commits that affect that file.
git log <file>
只显示影响该文件的提交。