使用 git 拉取特定版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26386037/
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
Pulling a specific version with git
提问by Habba
I need the source code from a specific version of a project (The SonarQubeproject), but I can't figure out how to pull it from git.
我需要特定版本的项目(The SonarQube项目)的源代码,但我不知道如何从 git 中提取它。
I've added the repo as a remote (git add remote origin
) and pulled the latest version from the master branch, but that is not the version I need.
我已将 repo 添加为远程 ( git add remote origin
) 并从 master 分支中提取了最新版本,但这不是我需要的版本。
I know the commit I need is d25bc0e
, but when I try "git fetch origin master d25bc0e
" I get the error "fatal: couldn't find remote ref d25bc0e
".
我知道我需要的提交是d25bc0e
,但是当我尝试“ git fetch origin master d25bc0e
”时出现错误“ fatal: couldn't find remote ref d25bc0e
”。
It could be I'm doing something very wrong, I am not very experienced with Git.
可能是我做错了什么,我对 Git 不是很有经验。
回答by VonC
You cannot pull a specific commit.
你不能拉一个特定的提交。
See more at "Pull a specific commit from a remote git repository"
多见于“拉特定从远程git仓库提交”
Once cloned, you can checkout a specific commit (but you would be in a detached branch mode, which is ok if all you need to do is read, and not commit)
克隆后,您可以签出特定的提交(但您将处于分离分支模式,如果您需要做的只是读取而不是提交,则可以)
git checkout d25bc0e
If you had to do some modification, starting from that commit, you would create a new branch:
如果你必须做一些修改,从那个提交开始,你将创建一个新分支:
git checkout -b newBranch d25bc0e
Note: since Oct. 2014, you might be able to fetch only one commit(Git 2.5, June 2015), only if the remote server allows it.
But here, I would still recommend the classic workflow (clone+checkout).
注意:自 2014 年 10 月起,您可能只能获取一次提交(Git 2.5,2015 年 6 月),前提是远程服务器允许。
但在这里,我仍然会推荐经典的工作流程(克隆+结账)。
回答by Malatesh Patil
If you want to get the specific version. You can get it via commit id.
如果要获取特定版本。您可以通过提交 ID 获取它。
You can get the commit id in logs.
您可以在日志中获取提交 ID。
So first try git logto get specific commit id
所以首先尝试git log来获取特定的提交 id
Then try
然后试试
git reset --hard commit_id
git reset --hard commit_id
But this will not allow you to commit the version. This is read only of a specific version.
但这将不允许您提交版本。这是只读的特定版本。