2

In developing for a work enviornment, we create a branch for each feature or fix we work on, and then merge to QA for testing.

Occasionally I find it's helpful to have a stash which contains console.logs' of debugging steps for a specific process. But I want to only have that be a subset of files in my working copy.

So, I am considering creating another branch for local use with commits which will be used later. Which don't reference a specific ticket necessarily.

So the question is, how can I take a specific commit in this "useful items" branch, and apply it to another branch? I'm sorry if I'm using the term cherry pick incorrectly here. I use sourcetree but am able to use command line for this also.

Oliver Williams
  • 5,966
  • 7
  • 36
  • 78

1 Answers1

3

there are several ways to achieve it (you have to be on the branch you want to apply the commit to),

you can create a patch of the commit you want then apply it

git format-patch <commit sha1> 
git apply <patch path>

or you can indeed cherry-pick the commit you want

git cherry-pick <commit sha1>
Oliver Williams
  • 5,966
  • 7
  • 36
  • 78
ponayz
  • 237
  • 4
  • 13
  • what is the difference between a patch and a cherry pick in this context and are there benefits/drawbacks between the two – Oliver Williams Apr 21 '16 at 18:40
  • i like cherry-pick better as it's only one commande line and doesn't generate file. The patch is usefull as it generate a texte file you can store on usb key and share on other computer if needed for example – ponayz Apr 22 '16 at 10:11