Pergunta

I'd like to make a copy of origin/master of a repo such that there are two side-by side trunks, with the second one, origin/develop. I want both trunks to have all of the same commits up to a certain point (which would the time origin/develop was created) but if you were to look at the very first commit, each trunk would have a different root. Is this possible?

Basically, my team has had one origin/master branch to work with but we'd like to move to something more like git-flow so there are multiple side by side trunks. Given that we've had all of this history we don't want to lose, how do you move to the git-flow model?

Here's the workflow:

origin/master                              
-> Initial Commit on origin/master         
-> SHA1                                    
-> SHA2                                    
-> SHA3                                    
-> SHA4                        

===> create a duplicate of origin/master as origin/develop

                 origin/develop
                 ->same initial commit that was on master
                 ->SHA1
                 ->SHA2
                 ->SHA3
                 ->SHA4
                 ->SHA5: committed to origin/develop only
                 ->SHA6: committed to origin/develop only

<=== merge develop (SHA5 & SHA6) into master at this point
Foi útil?

Solução 2

If I understand your question correctly, no - this is not possible. Each commit points to its parent commit. Modifying a parent will cause all subsequent commits (even though the patch is the same) to be different. git rebase handles that pretty well, but the following branch scheme will NOT be possible without merging the initial develop commit to master (which is not what I think you want):

o---o--o--o--o          (branch master)
  /|| || || ||\
 o--o--o--o--o-o--o--o  (branch develop)

When you change your initial commit, git will re-commit all the following commits (create a new hash for each commit), which will look like this:

o--o--o--o--o          (branch master)

o--o--o--o--o--o--o    (branch develop)

I don't understand why you need this, but git actually helps you save your history by using merges. When you merge, the history of the merged branch is merged with the merging branch, so after the merge you can clearly see what's going on with git log --graph.

On the other hand, if you have different histories in 2 branches but the actual patches are the same (like in my second illustration), you can use git rebase to make your history cleaner and linear, to look like this:

o--o--o--o--o          (branch master)
             \
              o--o--o  (branch develop)

Outras dicas

You don't need different roots? Just branch develop from current master and don't worry about it. If you look at the history (git log) from the end of the new develop branch you will see it all down the develop branch till the branch point and then master history back to the first commit in the repo. You won't loose any history.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top