views:

99

answers:

1

I have a branch that I would like to rebase onto the lastest commit on my master. The problem is that one of the intervening commits on master was to delete and ignore a particular set of files (see this question).

If I just do a straight rebase, those files will get deleted again. Is there anyway of doing this, inside git, rather than copying all the files out by hand, then copying them back in again afterwards?

Or should I do something like create a new branch off master, then merge in just the commits from the old branch?

Attempts ascii art:

master    branch
  |        w  work in progress on branch
  C        |  committed further changes on master
  |        |
  B        /  committed delete/ignore files on master
  |       2  committed changes on branch
  |      /  
  A     /  committed changes on master which I now need to get branch working
  |    1  committed changes on branch
  0___/  created branch

(Doing the art, I realise that I could just rebase branch from A, then merge when I've finished, but I'd still like to know if there's a way to do this 'properly')

UPDATE Warning to anyone trying this. The solution proposed here is fine, but when you checkout master again, the B commit will be re-applied, and you lose all your files again :(

+1  A: 

From your comment, I gather you need to rebase dev branch on top of master except B.
You do not want to see files you removed in one branch be removed in another.

One possible solution would be:

  • rebase --interactive master to rewrite commits order (if possible)
    0--A--C'--B'  master
     \
      --1--2--w     dev
  • rebase dev branch on top of C' (representing all the master commit except B)
    0--A--C'--B' master 
           \
            --1'--2'--w' dev

That means you do not have already pushed master to another repository (otherwise, that would involve a merge nightmare for those who wish to pull master in their own repo/master branch)

VonC
In the end, I went with rebasing on the commit before the one that 'hurts'. But the green tick is yours.
Benjol