0

I have 3 branch in my git repo: master, stand and develop. For each feature i create new brach from develop. After feature done, i'll merge it branch into develop (with --no-ff option).

For example, i have 3 feature (f1, f2, f3) merged branches in develop, and i removed f1, f2, f3 (or it was created on another machine and developer doesn't pushed it into origin repo) after merging into develop. And now i want to "put" f1 and f3 to stand branch (it have more than one commit in it and i can't use cherry-pick) what should i do?

Sure, i can create cherry-pick script for revision range merging, but maybe, i have a better way to merge it (by old branch name, or something else).

my repo:
develop          ---
               /
stand      ---
          /
master ---

feature branches:
          f1   f2   f3
         /  \ /  \ /  \
develop ----------------

i want:  f1   f2   f3
develop ----------------       
stand   -----    -------

Thanks.

Alexey Kutuzov
  • 679
  • 8
  • 22

3 Answers3

1

You should be able to cherry-pick the merge commits (created after merging two branches), which theoretically should do what you want.

rubenvb
  • 74,642
  • 33
  • 187
  • 332
  • Yes, i had read [this](http://stackoverflow.com/questions/1994463/how-to-cherry-pick-a-range-of-commits-and-merge-into-another-branch) topic , but i want a little something: just tell git "hey, some times ago i had branch with name f1, but now i merged it into develop and removed it. now, please, transfer all affected by f1 changes from develop into stand." – Alexey Kutuzov Aug 31 '11 at 14:47
  • @Alexey Kutuzov Hold on, "removed it"? Then you're stuck with cherry-picking, aren't you? Were you looking for some way to recover the branches from deleted history? – ANeves Aug 31 '11 at 14:58
  • @rubenvb, i'm really sorry - question was not correct (fixed now). Sure, i haven't branches any more. – Alexey Kutuzov Aug 31 '11 at 15:03
  • Still, the merge commit in your "develop" branch should still be there, although I frankly don't have any first-hand experience with this particular situation. Try to find the merge commit with the graphical `gitk` utility. – rubenvb Aug 31 '11 at 15:07
  • Yep, _gitk_ still shown branches correctly. I think that _gitk_ can found info about that branches (because it's no fast-forwarded) we can do it too. But i don't know how. – Alexey Kutuzov Aug 31 '11 at 15:17
1

You could:

  1. create branch f1_cpy (on f1) and branch f3_cpy (on f3), these are the two copies which you will move/apply;
  2. checkout to f1_cpy, rebase it to stand and then merge it to stand;
  3. checkout to f3_cpy, rebase it to stand (which now includes f1_cpy) and then merge f3_cpy to stand.

This is in practice like cherry-picking, but maybe simpler to understand and manage/use.

The use of copy-branches is so you don't destroy your real history when something goes wrong.
If you do not use copy-branches and and end up loosing precious history... take a deep breath and dive into git reflog.
But do use copies, so you can play around at will.

Juggling knives is only awesome until you get hurt. :|
(I learned my lesson about git-rebase.)

ANeves
  • 6,219
  • 3
  • 39
  • 63
1

If you don't have the branches anymore, luckily you used --no-ff so they can be recovered. Look in gitk and find the SHA1 of the last commit before the merge commit on develop for feature 1. Then to get it back just do:

git branch f1 SHA1

Then to put them on stand, do:

git rebase --onto stand develop f1
git checkout stand
git merge f1

git rebase --onto stand develop f3
git checkout stand
git merge f3
Karl Bielefeldt
  • 47,314
  • 10
  • 60
  • 94
  • Beautiful, thanks. One more question: if i created branch f3 on develop after someone commit anything, it will merged too? – Alexey Kutuzov Sep 01 '11 at 13:47
  • This particular method is only going to merge the changes actually made after `f3` branched off. It won't pull in `f2`, for example. There are other ways to pull it in if that's what you want. – Karl Bielefeldt Sep 01 '11 at 14:50