gerrit - git(pull vs checkout vs cherrypick)这是为了什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26460415/
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
gerrit - git (pull vs checkout vs cherrypick) which is for what?
提问by mk..
In Android's gerrit ex: link, to download the patch, I see 4 options.
在 Android 的 gerrit ex: link 中,要下载补丁,我看到了 4 个选项。
- repo download
- checkout
- pull
- cherry-pick
- 回购下载
- 查看
- 拉
- 樱桃采摘
What is the difference between them?
它们之间有什么区别?
Here is what I think of them. Please clarify
这是我对他们的看法。请说清楚
- repo download --> Downloads full source code(of all git repos in the project) till this commit
- checkout --> Not sure what it is.
- pull --> Not sure what it does?
- cherry-pick --> It tries to download only this change and merge it into the source code.
- repo download --> 下载完整的源代码(项目中的所有 git repos)直到这次提交
- 结帐 --> 不确定它是什么。
- pull --> 不知道它有什么作用?
- cherry-pick --> 它尝试仅下载此更改并将其合并到源代码中。
I know that pull and checkout are different from cherry-pick. But how are they different?
我知道 pull 和 checkout 与cherry-pick 不同。但是它们有什么不同呢?
采纳答案by Akash Agrawal
You are right about the first one. Here are the rest of them:
你是对的第一个。以下是其余的:
Checkout: Fetchesthe latest changes. You should already have this repo downloaded. It does not mergethose new changes but makes your working directory reflect them. You can merge them at your leisure later.
Pull: Fetchesthe changes AND mergesthem into the local branch of the same name.
Cherry-pick: Fetchesthe commit and plays it on top of the current local branch, thus creating an entirely new commitwhich happens to have same changes as the one it fetched.
Checkout:获取最新更改。你应该已经下载了这个 repo。它不会合并这些新更改,而是让您的工作目录反映它们。您可以稍后在闲暇时合并它们。
Pull:获取更改并将它们合并到同名的本地分支中。
Cherry-pick:获取提交并在当前本地分支之上播放,从而创建一个全新的提交,该提交恰好与它获取的提交具有相同的更改。
They are a little different than what they actually mean in git
. checkout
and cherry-pick
don't automatically fetch the changes. checkout
just takes HEAD
to a commit you specify, thus making working directory exactly as it was at that commit. Likewise, cherry-pick
is used to replay commits which you already have local access to.
它们与它们在 中的实际含义略有不同git
。checkout
并且cherry-pick
不要自动获取更改。checkout
只需HEAD
提交您指定的提交,从而使工作目录与该提交完全相同。同样,cherry-pick
用于重放您已经具有本地访问权限的提交。
回答by fejese
With git you have your own version of the repository. That you synchronise with others' repositories. With fetch
you update your remote references, ie. refresh what others got. With checkout
you switch to a specific revision. You want to do this, if you just started using this.
使用 git,您可以拥有自己的版本库。您与其他人的存储库同步。随着fetch
您更新您的远程引用,即。刷新别人得到的东西。随着checkout
您切换到特定修订版。如果你刚开始使用它,你想这样做。
Now if you are already following a remote branch, you might only need to update your local branch. That's what pull
does for you. It applies all the changes in the remote branch to your local one. You need this if you're using it already you just want to update.
现在,如果您已经关注远程分支,则可能只需要更新本地分支。这就是pull
为你所做的。它将远程分支中的所有更改应用于您的本地分支。如果您已经在使用它并且只想更新,则需要它。
cherry-pick
let you pick one change from anywhere in the repository and will apply it on your local branch. It is handy if you're on a different branch for any reason but still need that specific change. Be aware that if you cherry-pick without pushing that change that this change is not persistent. It's committed to your local repository but not to the remote (it might be what you need in cases though).
cherry-pick
让您从存储库中的任何位置选择一项更改并将其应用于您的本地分支。如果您出于任何原因在不同的分支上但仍需要进行特定更改,这将很方便。请注意,如果您在不推动该更改的情况下进行挑选,则此更改不会持久。它提交给您的本地存储库,但不提交给远程存储库(尽管在某些情况下它可能是您需要的)。
See more about git basics for example here
例如在这里查看更多关于 git 基础知识
回答by Matt
checkout: you want to use it when you are depending on a particular CHANGE in a branch. say your colleague has checked in some APIs for you to consume, and you can checkout that CHANGE to a new local branch and start working on your change.
结帐:当您依赖于分支中的特定更改时,您想使用它。假设你的同事已经签入了一些 API 供你使用,你可以签出该 CHANGE 到一个新的本地分支并开始处理你的更改。
Cherrypick: you want to apply a particular CHANGE to your local branch or a particular release branch, then you cherrypick. Imagine you have a patch fix in your 1.1 release, and you want to apply that fix/CHANGE to your 2.0 branch, you can simply cherrypick it. It will create a new CHANGE in your 2.0 branch containing the fix.
Cherrypick:您想将特定的 CHANGE 应用到您的本地分支或特定的发布分支,然后您选择。假设您在 1.1 版本中有一个补丁修复,并且您想将该修复/更改应用到您的 2.0 分支,您可以简单地挑选它。它将在包含修复程序的 2.0 分支中创建一个新的 CHANGE。
here is a graphical representation: http://think-like-a-git.net/sections/rebase-from-the-ground-up/cherry-picking-explained.html
这是一个图形表示:http: //think-like-a-git.net/sections/rebase-from-the-ground-up/cherry-picking-explained.html