How do criss-cross merges arise in Git?

后端 未结 4 731
故里飘歌
故里飘歌 2020-12-17 23:24

I have been going through the, \"git merge-base\", man page and I can\'t understand how multiple merge bases develop. Specifically, I\'m hung up on the following illustratio

4条回答
  •  猫巷女王i
    2020-12-18 00:27

    Here is a sequence of commits that would generate a criss-cross merge. More steps than the one involving the --amend, but only uses the basics. Run this script to see that you do indeed get a criss-cross merge.

    #!/bin/sh
    # Initialize 
    git init .                                                                                                                       
    echo date > file.txt; git add file.txt
    git commit -m "Initial commit"
    
    # Make branches                                                                                                                     
    git branch A; git branch B
    
    # Make change in A                                                                                                                  
    git checkout A
    echo date > fileA.txt; git add fileA.txt
    git commit -m "first commit along branch A"
    
    # Make change in B; add tag for later                                                                                                               
    git checkout B
    echo date > fileB.txt; git add fileB.txt
    git commit -m "first commit along branch B"
    git tag "tag-B"
    
    # Merge A into B (still on B)                                                                                                       
    git merge --no-edit A; git tag "M"
    
    # Add another commit on B whose parent is M                                                                                         
    echo date > fileB2.txt; git add fileB2.txt
    git commit -m "second commit along B"
    
    # Switch to A and add a commit; note that
    # M is not an ancestor of this commit                                                                          
    git checkout A
    echo date > fileA2.txt; git add fileA2.txt
    git commit -m "second commit along A"
    
    echo "Best common ancestors (before criss-cross):"
    # Should be only one
    git merge-base --all A B
    
    # Merge the commit tagged "tag-B" 
    # into A generating the cris-cross-merge                                                            
    git merge --no-edit tag-B
    
    echo "Best common ancestors (after criss-cross):"
    # Should be two
    git merge-base --all A B
    

提交回复
热议问题