2012-07-31 9 views
12

ho appena trovato strumento git-sotto-albero che qualche tempo fa è diventato una parte della git principale repo https://github.com/apenwarr/git-subtree/Qual è la differenza tra git merge sottostruttura e git-sottostruttura

Tuttavia non capisco appieno ciò che la funzionalità questo strumento fornisce oltre il già esistente "git read-tree" + "git merge -s sottostruttura". È l'unico scopo di git-sottostruttura - rendere la cronologia dei commit risultante migliore o ha più funzionalità che ho trascurato?

risposta

12

I comandi descritti descrivono una sottostruttura in un repository. Il comando git-subtree ha molte più opzioni, come descritto da the documentation. Tra gli altri, è possibile (annotati per semplicità):

add:: 
    Create the <prefix> subtree by importing its contents 
    from the given <refspec> or <repository> and remote <refspec>. 
merge:: 
    Merge recent changes up to <commit> into the <prefix> 
    subtree. 
pull:: 
    Exactly like 'merge', but parallels 'git pull' in that 
    it fetches the given commit from the specified remote 
    repository. 
push:: 
    Does a 'split' (see above) using the <prefix> supplied 
    and then does a 'git push' to push the result to the 
    repository and refspec. This can be used to push your 
    subtree to different branches of the remote repository. 
split:: 
    Extract a new, synthetic project history from the 
    history of the <prefix> subtree. The new history 
    includes only the commits (including merges) that 
    affected <prefix>, and each of those commits now has the 
    contents of <prefix> at the root of the project instead 
    of in a subdirectory. Thus, the newly created history 
    is suitable for export as a separate git repository. 

ci sono anche una varietà di flag che aiuti e manipolare quanto sopra. Credo che tutte queste opzioni fossero disponibili prima tramite catene di comandi idraulici. git-subtree.sh li avvolge e li rende notevolmente più facili da eseguire.

5

Se si guarda il vecchio codice della sottostruttura prima di essere aggiunto a git come modulo contrib: https://github.com/apenwarr/git-subtree/blob/master/git-subtree.sh si può vedere che lo strumento sottostruttura git è in realtà un wrapper più avanzato attorno alle strategie di fusione dei sottostrati git di livello inferiore.

Fondamentalmente sfrutta tali strategie in modo sensato per semplificare la gestione dei sottotitoli. In particolare la roba --squash è davvero, davvero utile.