February 24, 2010

Git Cherry-pick

Boss says: I’m thinking we need the app to say the abc’s…make me a prototype

Person 2:

  • git pull
  • git branch abc
  • git checkout abc
  • touch abc.rb
  • edit abc: puts 'abcdefgh' (pretend this takes you a really long time & is really hard)

    Boss says to Person 1: ARRRG! You made count.rb with 444, not 4! Don’t you know how to count to 10? Fix it!

Person 1:

  • git checkout master
  • change count.rb so that it counts correctly
  • git add .
  • git commit -m "fixed bug in count.rb"
  • git push

Person 2

  • git checkout master
  • git pull
  • git log
  • find the sha for the commit called “fixed bug in count.rb”, copy it
  • git checkout abc
  • git cherry-pick master <sha you copied>

git cherry-pick is good for including a particular bug fix that was developed on a different branch into the branch you are working on.

1 Comment