1

I am new to git related platforms, currently working primarily with github and gitlab on the side for project purposes. I have a confusion regarding an abstract terminology, it's related to fetching commits(perhaps unmerged or in different branch or from anywhere within a repo).

As far as I understand, we use cherry-picking when there are two branches(refactor,master) in a repository, and we want to pick a particular commit(X) out of one branch(refactor) and get in it another branch (master). (According to numerous sources out in the interweb)

Is it possible to cherry-pick within a same branch? Is that even why cherry-pick exist?

Someone told me that cherry-pick does not have to do with branches at all, that abstractly "cherry-pick" in general stands for just picking any commit from anywhere (same or different branch)

Let me give an example scenario.

Let's say we have a master branch, and some people have sent some pull requests, which are yet to be committed, and someone wants to fetch those commits to test them before they get merged... I know how to fetch that commit, but my question is, is doing that known as "cherry-pick"? That cherry-pick does not have to do with branches?

Thank you for reading.

Skynet094
  • 443
  • 4
  • 19
  • If someone wants to test a branch, why wouldn't they just fetch and then checkout that branch? – Oliver Charlesworth Nov 14 '18 at 22:45
  • Let's say, that they just want a single commit out of that test branch and check it out with other stuff in master which may not be available in the test branch. – Skynet094 Nov 14 '18 at 22:47

1 Answers1

1

Is it possible to cherry-pick within a same branch? Is that even why cherry-pick exist?

No.

What you can do is:

  • fetch the remote branch, referenced in your repo as origin/master
  • create a test branch from your current master (unchanged because you didn't git pull, just git fetch)
  • cherry-pick a commit from origin/master into test, for testing

In your case:

  • import your pull-request
  • checkout a test branch from your master
  • do a simple merge from that PR branch (or a cherry-pick if want just a few commits of that PR branch)
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250