gerrit - git (pull vs checkout vs cherrypick) which is for what?

后端 未结 3 1626
Happy的楠姐
Happy的楠姐 2021-01-30 10:16

In Android\'s gerrit ex: link, to download the patch, I see 4 options.

  1. repo download
  2. checkout
  3. pull
  4. cherry-pick

What is th

相关标签:
3条回答
  • 2021-01-30 10:51

    You are right about the first one. Here are the rest of them:

    1. Checkout: Fetches the latest changes. You should already have this repo downloaded. It does not merge those new changes but makes your working directory reflect them. You can merge them at your leisure later.

    2. Pull: Fetches the changes AND merges them into the local branch of the same name.

    3. Cherry-pick: Fetches the commit and plays it on top of the current local branch, thus creating an entirely new commit which happens to have same changes as the one it fetched.

    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.

    0 讨论(0)
  • 2021-01-30 11:06

    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.

    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.

    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).

    See more about git basics for example here

    0 讨论(0)
  • 2021-01-30 11:16

    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.

    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.

    here is a graphical representation: http://think-like-a-git.net/sections/rebase-from-the-ground-up/cherry-picking-explained.html

    0 讨论(0)
提交回复
热议问题