четверг, 10 января 2013 г.

Git: cherry-pick vs rebase

When to use cherry-pick and when to use rebase?

Cherry-pick is a tool to merge a single isolated commit into your current branch.

Consider an example. Here we have two branches: master and topic-test. Our current branch is master.


If we happen to cherry-pick "change 2" commit, we are going to get only the changes introduced by "change 2" commit but not "change 1" commit because cherry-picking ignores history.


Rebase is way to "copy and paste" all commits from other branch on top of your current branch. Rebasing "change 2" above master results in:


Please note the difference: now the whole history was merged.

Both of theese operations are merges, so they both can result in conflicts which have to be resolved before continuing. Rebase processes one commit after another, so can result in many tiers of conflicts. 

Комментариев нет:

Отправить комментарий