merge - How do I manage merging and rebasing in git? -


i git purpose of rebase. makes sense me. i have feature branch i'm working on , i'm ready put master branch rebase squash of commits 1 clean 1 it's integrated master without messy history. right?

here's we've been doing.

  1. create feature branch
  2. add bunch of commits build feature
  3. periodically merge master branch feature branch (in order avoid painful merge down road)
  4. when done, merge feature branch master

the problem i'm seeing periodically merging master feature branch causes problems when rebasing because have bunch of master branch checkins mixed in amongst feature checkins.

what's right workflow here? following commads come play:

  • git rebase -i head^#
  • git rebase master
  • git merge master
  • git-rerere
  • git reset --hard head^

you should merge to/from master once, @ end of life of branch. idea of feature/topic branch contains changes relevant feature; lose when merge in master repeatedly. (you can read junio hamano, git maintainer, says branches.)

you can "practice" merge, throw away, , use git-rerere have git automatically record merge resolutions, can re-used when ready merge. see http://www.kernel.org/pub/software/scm/git/docs/git-rerere.html background , tutorial. cool because lets work of merge, without committing anywhere explicitly, , work "magically" when ready create merge. so, instead of 1 big painful merge @ end, can bunch of smaller, simpler, intermediate "practice" merges along way. speaking:

# enable rerere git config --global rerere.enabled 1 # start feature branch git checkout -b feature # hack hack hack git commit git commit # practice merge git merge master # ...then throw merge commit away, work saved rerere git reset --hard head^ # hack hack hack git commit # merge master, reusing saved work rerere git checkout master git merge feature git branch -d feature 

see http://progit.org/2010/03/08/rerere.html tutorial.

you can periodically rebase topic branch on top of master , merge @ end.

to deal situation 1 in, topic branch (say named feature) has series of merges main mixed various in-progress commits, easiest approach squashed merge produce "merged" working tree , create new commit (or series of commits) on main. example:

git checkout master git merge --squash feature git commit 

this produce single commit represents state of tree @ head of feature, merged master.

of course, can regular merge master change, leaving messy history of feature present, , work more cleanly in future. e.g., simply

git checkout master git merge feature 

and move on.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -