Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git merge against an arbitrary base revision (git-svn)

I'm using git-svn for offline development against my company's Subversion repository, which is the project's repository of record. To enable management visibility I'm required to maintain my feature branches in SVN. Sometimes I need to merge changes from our trunk to a feature branch multiple times over the lifetime of the branch. Since I'm required to keep the branch up-to-date in SVN I have to merge; I can't rebase commits once they're pushed to SVN. Further, git svn dcommit removes the second parent from merge commits. That means on merges after the first git merge identifies the branch root as the merge base instead of the most recent merge parent. It therefore tries to re-merge changes that have already been merged, which pretty much guarantees nasty conflicts.

When I merge in SVN I manually specify the base revision:

svn merge -r 49262:49608 $svn/trunk

Is there a way in git to do a merge with a manually specified base revision like that?

Update:

Note that I need to specify two revisions, both the base and the parent revision. I have a history like

trunk: A -- B -- C -- D -- H -- I
             \         \
    feature:  E -- F -- G -- J -- K

but git svn dcommit has removed the parent relationship between G and D. I need to run a merge of I on to K with a base of D. Simply running

$ git checkout feature
$ git merge trunk

will try to merge I on to K with a base of B instead of D, which re-applies C and D resulting in extreme merge conflicts. With SVN I would run a command like

$ svn switch $svn/feature
$ svn merge -r D:I $svn/trunk

but git merge does not have an option to specify the base revision D. I'm looking for something like

$ git merge --base D trunk

but such an option doesn't appear to exist.

like image 893
Sam Hanes Avatar asked Oct 03 '22 11:10

Sam Hanes


1 Answers

(edit: for a lower-level way of doing this see previous revisions, this way's fastest though)

  • make a nonce commit with feature's tree parented on the correct merge base

    git checkout `git commit-tree -p $D -m - feature^{tree}`
    
  • merge trunk into that as usual

    git merge trunk --no-commit
    git commit    # the two-stepper gets the commit message someplace known
    
  • commit the merged tree as the new feature tip

    git commit-tree -p feature -p trunk -F .git/COMMIT_EDITMSG HEAD^{tree} \
            | xargs git checkout -B feature
    

like image 140
jthill Avatar answered Oct 09 '22 18:10

jthill