tags:

views:

206

answers:

3

I need to insert a commit in the master branch of my git repository whist preserving the subsequent merges and commits.

I currently have something like this

A--B--C--D--E--F     master
       \     \  
        G--H  I--J   branches

and need to insert a commit K such that the new structure becomes

A--B--K              master
    \
     C--D--E--F      new branch
      \     \  
       G--H  I--J    old branches

I'm not even sure if this is possible. Any ideas?

+1  A: 

Rename the "master" branch to "new branch". Then checkout the commit B, start a new branch called "master" from there, and make your changes. Something like follows should do it (not tested).

git branch -m master new_branch
git branch master B
git checkout master
Esko Luontola
Thank you for your answer. This results in commit A being a member of "new branch" and not "master". The history for master then becomes "B--K" rather than the intended "A--B--K". This same structure could be achieved (with differing branch names) by simply branching from B and committing K.
A: 
# git checkout -b new-master B

Now make your changes for K, commit them and voilá, there’s the structure you want. :)

Bombe
+5  A: 
git checkout master
git branch new_branch # copy current branch master to new_branch
git reset --hard B    # now master points to B
(hack, hack, hack)
git commit -m K       # K on B in master
Banengusk
This results in the required structure - thank you!