如何从 git 中提取特定的提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50942519/
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 to pull a specific commit from git
提问by Manu Chadha
My code isn't working and it seems I have merged a wrong piece of code in my master
branch. I am unable to pin point the issue and thus I want to pull specific commits one by one to find out which version was working just before the wrong commit.
我的代码不起作用,似乎我在我的master
分支中合并了一段错误的代码。我无法指出问题所在,因此我想一一提取特定的提交,以找出在错误提交之前哪个版本正在工作。
How could I pull a specific commit? Eg, On Bitbucket, I see a merge with id 9ce920d
on branch test
but I don't know how to pull this merge.
我怎么能拉一个特定的提交?例如,在 Bitbucket 上,我9ce920d
在分支上看到与 id 的合并,test
但我不知道如何进行合并。
回答by kabanus
The question has wrong terminology. You cannot pull a commit, you can only checkout a commit. Pulling a commit would defy the whole branch/commit structure saving memory. You pull all commits in a branch, and if you want to check out a specific one, then well, check it out:
这个问题有错误的术语。你不能拉一个提交,你只能签出一个提交。拉提交将无视整个分支/提交结构节省内存。你拉取一个分支中的所有提交,如果你想查看一个特定的提交,那么,查看它:
git checkout 9ce920d
You will be in headless mode (no pointer to the commit, unless by chance you have a branch on it), so you may want to create a branch if you want to mess around.
你将处于无头模式(没有指向提交的指针,除非你有一个分支),所以如果你想搞砸,你可能想要创建一个分支。
回答by Neli
git checkout <id>
should do the trick. Where 'id' is the specific commit you want to get.
应该做的伎俩。其中“id”是您想要获得的特定提交。