Git subtree en detalle

Al decidir utilizar esta o aquella herramienta en sus propios proyectos, el ingeniero no solo debe estudiar la documentación de respaldo, sino también realizar una serie de experimentos para evitar posibles problemas en el futuro. Si hablamos de una política CM, diseñada a largo plazo, el precio del error de elección se vuelve bastante alto.


El propósito de este documento es practicar la herramienta de gestión de subárbol Git .



A partir de la revisión 1.7.11 , el repositorio ascendente de Git , en el directorio contrib / subtree , contiene una herramienta para automatizar el trabajo con subárboles .


El servicio git-subtree (1) es en realidad un complemento útil que utiliza las funciones git-read-tree (1) y git-write-tree (1) . Por lo tanto, los enlaces en los comandos add / pull / push de git-subtree (1) :

git subtree add --prefix=<subdir> <remote> <ref> 

pueden ser nombres de sucursales o nombres de etiquetas de un repositorio remoto.


Además, si agrega el repositorio remoto al archivo de configuración del repositorio local .git / config de antemano, utilizando el comando:


 bash-4.4$ git remote add build-system ../../remote/build-system.git 

donde build-system es el nombre del repositorio remoto ../../remote/build-system.git , luego, usando los comandos add / pull / push de git-subtree (1) , podemos referirnos al repositorio / repositorio remoto build-system.git por nombre.


Por el momento, git-subtree (1) prácticamente no se está desarrollando, sino que solo se mantiene actualizado para el grado actual de desarrollo del proyecto Git .


Sin embargo, git-subtree (1) es la herramienta más popular y poderosa para trabajar con subárboles.



Entorno de prueba


En el artículo anterior de git-subrepo (1) , utilizamos una estructura de directorio simple con repositorios de prueba para demostrar cómo funcionan las funciones en la práctica. Ahora reproducimos el siguiente entorno:


 bash-4.4$ vim _init.sh #!/bin/sh CWD=`pwd` mkdir remote owner user cd remote git init --bare build-system.git git init --bare platform.git cd ../owner git clone $CWD/remote/build-system.git git clone $CWD/remote/platform.git cd build-system echo -e "\n[master] build-system 1.0.0\n" >README git add README git commit -m "init build-system master 1.0.0" git push cd ../platform echo -e "\n[master] platform 1.0.0\n" >README git add README git commit -m "init platform master 1.0.0" git push cd ../../user git clone $CWD/remote/build-system.git git clone $CWD/remote/platform.git cd $CWD :wq bash-4.4$ chmod a+x ./_init.sh bash-4.4$ ./_init.sh bash-4.4$ 

Aqui


dueño-directorio de trabajo del autor del proyecto;
remoto-Un directorio que representa el servidor del autor de los proyectos, en el que se encuentran los repositorios aguas arriba de la plataforma de proyecto principal.git y el subproyecto build-system.git ;
usuario-Directorio de trabajo para un usuario o miembro de un equipo de desarrollo

Como objetivos de estudiar las posibilidades de git-subtree (1), consideraremos las mismas tareas de las que hablamos en el artículo de Git Subrepo , pero teniendo en cuenta las diferencias entre las dos herramientas.



Conectar subárbol


Recuerde el estado actual del repositorio remoto / platform.git :


 bash-4.4$ bash-4.4$ cd owner/platform/ bash-4.4$ git log commit 7fad4becbd13258216fb95cbe9d987dd33f0be6d (HEAD -> master, origin/master) Author: user <___@_______> Date: Thu Nov 1 20:16:33 2018 +0300 init platform master 1.0.0 bash-4.4$ 

y conecte la rama maestra del repositorio ascendente remote / build-system.git al directorio del sistema de compilación:


 bash-4.4$ bash-4.4$ git subtree add --prefix=build-system ../../remote/build-system.git/ master git fetch ../../remote/build-system.git/ master warning: no common commits remote: Enumerating objects: 3, done. remote: Counting objects: 100% (3/3), done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From ../../remote/build-system * branch master -> FETCH_HEAD Added dir 'build-system' bash-4.4$ 

Considere el nuevo estado de la copia local del repositorio remoto / platform.git :


 bash-4.4$ bash-4.4$ git log --graph * commit 47905bcb80be6f7cb3030513986fad4df548f812 (HEAD -> master) |\ Merge: 7fad4be 783c6d5 | | Author: user <___@_______> | | Date: Thu Nov 1 20:20:20 2018 +0300 | | | | Add 'build-system/' from commit '783c6d5af1100e9665f930c818c861ff011bed19' | | | | git-subtree-dir: build-system | | git-subtree-mainline: 7fad4becbd13258216fb95cbe9d987dd33f0be6d | | git-subtree-split: 783c6d5af1100e9665f930c818c861ff011bed19 | | git-subtree-repo: ../../remote/build-system.git/ | | git-subtree-ref: master | | | * commit 783c6d5af1100e9665f930c818c861ff011bed19 | Author: user <___@_______> | Date: Thu Nov 1 20:16:33 2018 +0300 | | init build-system master 1.0.0 | * commit 7fad4becbd13258216fb95cbe9d987dd33f0be6d (origin/master) Author: user <___@_______> Date: Thu Nov 1 20:16:33 2018 +0300 init platform master 1.0.0 bash-4.4$ 

Aquí debe prestar atención al mensaje que dejó el comando git-subtree (1) add . De hecho, usando este comando, ponemos la diferencia en el repositorio de la plataforma :


 bash-4.4$ bash-4.4$ git diff 7fad4becbd13258216fb95cbe9d987dd33f0be6d 47905bcb80be6f7cb3030513986fad4df548f812 diff --git a/build-system/README b/build-system/README new file mode 100644 index 0000000..73a41c7 --- /dev/null +++ b/build-system/README @@ -0,0 +1,3 @@ + +[master] build-system 1.0.0 + bash-4.4$ 

Además, cuando el historial de cambios va un poco más allá, estudiaremos los detalles de la conexión de subárboles con más detalle, y ahora colocaremos nuestros cambios en el repositorio ascendente remote / platform.git :


 bash-4.4$ bash-4.4$ git push Enumerating objects: 6, done. Counting objects: 100% (6/6), done. Delta compression using up to 4 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (5/5), 582 bytes | 582.00 KiB/s, done. Total 5 (delta 0), reused 0 (delta 0) To ../../remote/platform.git 7fad4be..47905bc master -> master bash-4.4$ 

y vuelva a mirar la publicación de comando git-subtree (1) add :


  Add 'build-system/' from commit '783c6d5af1100e9665f930c818c861ff011bed19' git-subtree-dir: build-system git-subtree-mainline: 7fad4becbd13258216fb95cbe9d987dd33f0be6d git-subtree-split: 783c6d5af1100e9665f930c818c861ff011bed19 git-subtree-repo: ../../remote/build-system.git/ git-subtree-ref: master 

Estos mensajes son útiles para que, si es necesario, pueda encontrar el historial de conexión y el estado actual del subárbol. El comando original git-subtree (1) no agrega las dos últimas líneas del mensaje. Modificamos ligeramente esta utilidad para facilitar la búsqueda de información sobre cuándo y desde qué rama del repositorio remoto se creó este o aquel subárbol de nuestro proyecto.


Puede obtener el archivo de diferencias completo de nuestros cambios de la siguiente manera:


 bash-4.4$ bash-4.4$ git clone https://github.com/radix-platform/git.git bash-4.4$ cd git bash-4.4$ git checkout git-subtree-2.19.1 bash-4.4$ git diff v2.19.1 > ../git-subtree-2.19.1.patch bash-4.4$ 

Para que nuestros ejemplos sean más realistas, realizaremos cambios en el repositorio ascendente remote / build-system.git :


 bash-4.4$ bash-4.4$ cd owner/build-system/ bash-4.4$ vim README bash-4.4$ cat README [master] build-system 1.0.1 bash-4.4$ 

Guarde estos cambios:


 bash-4.4$ bash-4.4$ git add README bash-4.4$ git commit -m "update build-system version to 1.0.1" [master e5c5446] update build-system version to 1.0.1 1 file changed, 1 insertion(+), 1 deletion(-) bash-4.4$ 

y pasarlos al repositorio ascendente remoto / build-system.git :


 bash-4.4$ bash-4.4$ git push Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Writing objects: 100% (3/3), 274 bytes | 274.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To ../../remote/build-system.git 783c6d5..e5c5446 master -> master bash-4.4$ 

Entonces, la revisión del repositorio del sistema de compilación ha cambiado de 783c6d5 a e5c5446:


 bash-4.4$ bash-4.4$ git log commit e5c5446967599065dc02a269d8fcfc2c1d3c4f65 (HEAD -> master, origin/master) Author: user <___@_______> Date: Thu Nov 1 20:26:52 2018 +0300 update build-system version to 1.0.1 commit 783c6d5af1100e9665f930c818c861ff011bed19 Author: user <___@_______> Date: Thu Nov 1 20:16:33 2018 +0300 init build-system master 1.0.0 bash-4.4$ 

Recuerde este estado y continúe trabajando con el repositorio de contenedores remote / platform.git .



Recuperando cambios de un repositorio de subárbol ascendente


Digamos que todavía no conocemos los cambios en el repositorio ascendente del subárbol y estamos trabajando para mejorar el código de la plataforma :


 bash-4.4$ bash-4.4$ cd owner/platform/ bash-4.4$ vim README bash-4.4$ cat README [master] platform 1.0.1 bash-4.4$ bash-4.4$ git add README bash-4.4$ git commit -m "update platform version to 1.0.1" [master 442c9e9] update platform version to 1.0.1 1 file changed, 1 insertion(+), 1 deletion(-) bash-4.4$ bash-4.4$ git push Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Delta compression using up to 4 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 306 bytes | 306.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To ../../remote/platform.git 47905bc..442c9e9 master -> master bash-4.4$ 

Como resultado de nuestro trabajo, obtuvimos el siguiente estado del repositorio remoto / platform.git :


 bash-4.4$ bash-4.4$ git log --graph * commit 442c9e94c9890032fb2f3123661345d465e2849f (HEAD -> master, origin/master) | Author: user <___@_______> | Date: Thu Nov 1 20:41:40 2018 +0300 | | update platform version to 1.0.1 | * commit 47905bcb80be6f7cb3030513986fad4df548f812 |\ Merge: 7fad4be 783c6d5 | | Author: user <___@_______> | | Date: Thu Nov 1 20:20:20 2018 +0300 | | | | Add 'build-system/' from commit '783c6d5af1100e9665f930c818c861ff011bed19' | | | | git-subtree-dir: build-system | | git-subtree-mainline: 7fad4becbd13258216fb95cbe9d987dd33f0be6d | | git-subtree-split: 783c6d5af1100e9665f930c818c861ff011bed19 | | git-subtree-repo: ../../remote/build-system.git/ | | git-subtree-ref: master | | | * commit 783c6d5af1100e9665f930c818c861ff011bed19 | Author: user <___@_______> | Date: Thu Nov 1 20:16:33 2018 +0300 | | init build-system master 1.0.0 | * commit 7fad4becbd13258216fb95cbe9d987dd33f0be6d Author: user <___@_______> Date: Thu Nov 1 20:16:33 2018 +0300 init platform master 1.0.0 bash-4.4$ 

Ahora, sería bueno saber qué sucedió en el repositorio ascendente del subárbol del sistema de compilación mientras estábamos trabajando para mejorar el código en el repositorio principal de nuestro proyecto. Desplácese por los subárboles primero con el comando git subtree --list :


 bash-4.4$ bash-4.4$ git subtree --list build-system ../../remote/build-system.git/ branch master HEAD bash-4.4$ 

Este comando, en un formato simple, presenta el directorio del subárbol, la URL del repositorio ascendente del subárbol, el tipo de enlace (rama o etiqueta), el nombre del enlace, así como la revisión de la rama o etiqueta especificada del repositorio, cuyo código colocamos en nuestro subárbol. Sin embargo, recordamos que el desarrollo del subproyecto del sistema de compilación ha seguido adelante y señalar al jefe de la rama maestra ya no es válido. Más bien, este es un mensaje sobre lo que nos gustaría tener en nuestro repositorio, y no sobre el estado real de las cosas.


Para saber cuánto ha progresado el código en el repositorio ascendente de un subárbol, también debemos desplazarnos por los subárboles, pero usando la opción -d :


 bash-4.4$ bash-4.4$ git subtree -d --list Looking for externals... Commit: 47905bcb80be6f7cb3030513986fad4df548f812 build-system ../../remote/build-system.git/ branch master HEAD The 'build-system' subtree seems not updated: original revision: 783c6d5af1100e9665f930c818c861ff011bed19 remote revision: e5c5446967599065dc02a269d8fcfc2c1d3c4f65 You can update 'build-system' subtree by following command: git subtree pull --prefix=build-system ../../remote/build-system.git/ master bash-4.4$ 

Ahora, el resultado sugiere que mientras estábamos trabajando en el código del repositorio principal, la rama maestra del repositorio ascendente del subárbol del sistema de compilación siguió adelante. Además, el comando git subtree -d --list emitió una pista de que podemos obtener cambios en el repositorio de subárbol ascendente de la siguiente manera:


 bash-4.4$ bash-4.4$ git subtree pull --prefix=build-system ../../remote/build-system.git/ master remote: Enumerating objects: 5, done. remote: Counting objects: 100% (5/5), done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From ../../remote/build-system * branch master -> FETCH_HEAD hint: Waiting for your editor to close the file... 

Este comando, dado que no especificamos -m "mensaje de confirmación" , abre el editor con el texto del mensaje:


Compromiso de fusión 'e5c5446967599065dc02a269d8fcfc2c1d3c4f65'

# Ingrese un mensaje de confirmación para explicar por qué es necesaria esta fusión,
# especialmente si combina un flujo ascendente actualizado en una rama de tema.
# #
# Las líneas que comienzan con '#' se ignorarán y se anulará un mensaje vacío
# el compromiso.

Reemplace este texto con uno más informativo:


Extraiga los cambios del repositorio principal de build-system.git ascendente:

Compromiso de fusión 'e5c5446967599065dc02a269d8fcfc2c1d3c4f65'

Después de guardar este mensaje y cerrar el editor, obtenemos el siguiente resultado:


 Merge made by the 'recursive' strategy. build-system/README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) bash-4.4$ 

Es decir, recibimos cambios en el repositorio ascendente remote / build-system.git y los guardamos en el subárbol del sistema de compilación de la copia local del repositorio principal remote / platform.git .


Verifique el estado del repositorio local:


 bash-4.4$ bash-4.4$ git status On branch master Your branch is ahead of 'origin/master' by 2 commits. (use "git push" to publish your local commits) nothing to commit, working tree clean bash-4.4$ 

Para que otros usuarios del proyecto puedan recibir estos cambios, debemos ponerlos en el repositorio ascendente remote / platform.git :


 bash-4.4$ bash-4.4$ git push Enumerating objects: 9, done. Counting objects: 100% (8/8), done. Delta compression using up to 4 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (5/5), 583 bytes | 583.00 KiB/s, done. Total 5 (delta 0), reused 0 (delta 0) To ../../remote/platform.git 442c9e9..ea52eab master -> master bash-4.4$ 

Veamos qué contiene ahora la copia local del repositorio de la plataforma , así como el repositorio ascendente remote / platform.git :


 bash-4.4$ bash-4.4$ git log --graph * commit ea52eabd5910159efabd80adcf522f22bf6a2af2 (HEAD -> master, origin/master) |\ Merge: 442c9e9 e5c5446 | | Author: user <___@_______> | | Date: Thu Nov 1 20:48:05 2018 +0300 | | | | Pull changes from master of upstream build-system.git repository. | | | | Merge commit 'e5c5446967599065dc02a269d8fcfc2c1d3c4f65' | | | * commit e5c5446967599065dc02a269d8fcfc2c1d3c4f65 | | Author: user <___@_______> | | Date: Thu Nov 1 20:26:52 2018 +0300 | | | | update build-system version to 1.0.1 | | * | commit 442c9e94c9890032fb2f3123661345d465e2849f | | Author: user <___@_______> | | Date: Thu Nov 1 20:41:40 2018 +0300 | | | | update platform version to 1.0.1 | | * | commit 47905bcb80be6f7cb3030513986fad4df548f812 |\ \ Merge: 7fad4be 783c6d5 | |/ Author: user <___@_______> | | Date: Thu Nov 1 20:20:20 2018 +0300 | | | | Add 'build-system/' from commit '783c6d5af1100e9665f930c818c861ff011bed19' | | | | git-subtree-dir: build-system | | git-subtree-mainline: 7fad4becbd13258216fb95cbe9d987dd33f0be6d | | git-subtree-split: 783c6d5af1100e9665f930c818c861ff011bed19 | | git-subtree-repo: ../../remote/build-system.git/ | | git-subtree-ref: master | | | * commit 783c6d5af1100e9665f930c818c861ff011bed19 | Author: user <___@_______> | Date: Thu Nov 1 20:16:33 2018 +0300 | | init build-system master 1.0.0 | * commit 7fad4becbd13258216fb95cbe9d987dd33f0be6d Author: user <___@_______> Date: Thu Nov 1 20:16:33 2018 +0300 init platform master 1.0.0 bash-4.4$ 


Vemos que el estado inicial del repositorio remoto / build-system.git , en el momento en que estaba conectado como un subárbol de plataforma, era 783c6d5af1100e9665f930c818c861ff011bed19 . Sin embargo, mientras estábamos trabajando en el código en el repositorio de la plataforma , el estado del repositorio cambió y se volvió igual a e5c5446967599065dc02a269d8fcfc2c1d3c4f65 .

El estado inicial del sistema de compilación ( 783c6d5af1100e9665f930c818c861ff011bed19 ) ya estaba en la historia del repositorio de la plataforma cuando estaba en 442c9e94c9890032fb2f3123661345d465e2849f . Por lo tanto, necesitamos tomar el estado de la plataforma en 442c9e94c9890032fb2f3123661345d465e2849f y el estado del sistema de compilación en e5c5446967599065dc02a269d8fcfc2c1d3c4f65 , calcular la diferencia entre ellos y superponer la diferencia resultante en la rama maestra.


Esta es la operación estándar de fusionar ramas, cuya esencia se puede expresar mediante la fórmula


  p[n] = p[n-1] + diff(p[n-1], b[n]) 

donde


  p[n] = ea52eabd5910159efabd80adcf522f22bf6a2af2, p[n-1] = 442c9e94c9890032fb2f3123661345d465e2849f, b[n] = e5c5446967599065dc02a269d8fcfc2c1d3c4f65. 

Aquí p actúa como una rama maestra, yb , juega el papel de una rama que se había separado previamente de la maestra para crear una nueva funcionalidad.


Considere nuevamente el mensaje que la utilidad git-subtree (1) nos preparó durante la ejecución del comando git-subtree-pull :


  git subtree pull --prefix=build-system ../../remote/build-system.git/ master 


Compromiso de fusión 'e5c5446967599065dc02a269d8fcfc2c1d3c4f65'

# Ingrese un mensaje de confirmación para explicar por qué es necesaria esta fusión,
# especialmente si combina un flujo ascendente actualizado en una rama de tema.
# #
# Las líneas que comienzan con '#' se ignorarán y se anulará un mensaje vacío
# el compromiso.

Este mensaje contiene información importante para nosotros, es decir, la condición


  b[n] = e5c5446967599065dc02a269d8fcfc2c1d3c4f65 

en el que la rama maestra del repositorio remoto / build-system.git se encontraba antes de " subir " a la rama maestra del repositorio de la plataforma .


Por supuesto, no es muy conveniente ejecutar manualmente el mensaje de confirmación al ejecutar el comando git-subtree-pull , sin embargo, otra forma de pasarnos el estado


  b[n] = e5c5446967599065dc02a269d8fcfc2c1d3c4f65 

La utilidad git-subtree (1) , en este caso, simplemente no existe.


Si usamos el control -m


  git subtree pill -m "Our own message" ... 

entonces perderíamos el valor del estado b [n] y, nuestro comentario no sería informativo y, por lo tanto, completamente inútil.


Cabe señalar que después de que el estado de la rama maestra del repositorio del sistema de compilación se haya movido desde el punto de montaje original de 47905bcb80be6f7cb3030513986fad4df548f812 , siempre recibiremos notificaciones de cambios en remote / build-system.git mientras vemos la lista de subárboles conectados. En otras palabras, usando la opción -d en un comando:


  git subtree -d --list 

siempre dará como resultado un mensaje similar al siguiente:


 bash-4.4$ bash-4.4$ git subtree -d --list Looking for externals... Commit: 47905bcb80be6f7cb3030513986fad4df548f812 build-system ../../remote/build-system.git/ branch master HEAD The 'build-system' subtree seems not updated: original revision: 783c6d5af1100e9665f930c818c861ff011bed19 remote revision: e5c5446967599065dc02a269d8fcfc2c1d3c4f65 You can update 'build-system' subtree by following command: git subtree pull --prefix=build-system ../../remote/build-system.git/ master bash-4.4$ 

Esto sucederá porque toda la información sobre el subárbol conectado se encuentra en el mensaje que acompañó a la confirmación 47905bcb80be6f7cb3030513986fad4df548f812 :


 bash-4.4$ bash-4.4$ git show 47905bcb80be6f7cb3030513986fad4df548f812 commit 47905bcb80be6f7cb3030513986fad4df548f812 Merge: 7fad4be 783c6d5 Author: user <___@_______> Date: Thu Nov 1 20:20:20 2018 +0300 Add 'build-system/' from commit '783c6d5af1100e9665f930c818c861ff011bed19' git-subtree-dir: build-system git-subtree-mainline: 7fad4becbd13258216fb95cbe9d987dd33f0be6d git-subtree-split: 783c6d5af1100e9665f930c818c861ff011bed19 git-subtree-repo: ../../remote/build-system.git/ git-subtree-ref: master diff --cc build-system/README index 0000000,0000000..73a41c7 new file mode 100644 --- /dev/null +++ b/build-system/README @@@ -1,0 -1,0 +1,3 @@@ ++ ++[master] build-system 1.0.0 ++ bash-4.4$ 

y no hay otro repositorio de esta información.


Lo único es que ahora, después de cada actualización de la rama maestra del repositorio remoto / build-system.git , en el lado de la plataforma , al ejecutar el comando


  git subtree -d --list 

solo cambiará el valor de la cadena


  remote revision: e5c5446967599065dc02a269d8fcfc2c1d3c4f65 

y nosotros mismos tendremos que tomar decisiones sobre si necesitamos nuevos cambios en el subárbol del sistema de construcción o, por el momento, no son necesarios.


Sin embargo, no será difícil para nosotros ejecutar el comando pull tantas veces como lo necesitemos, porque si el repositorio remoto / build-system.git no tuvo cambios reales, el comando:


  git subtree pull --prefix=build-system ../../remote/build-system.git/ master 

dará un mensaje adecuado:


 bash-4.4$ bash-4.4$ git subtree pull --prefix=build-system ../../remote/build-system.git/ master From ../../remote/build-system * branch master -> FETCH_HEAD Already up to date. bash-4.4$ 


Obteniendo código por los usuarios


Ahora todos los usuarios del repositorio ascendente remote / platform.git pueden obtener un árbol fuente completamente configurado con un solo comando git-pull (1) :


 bash-4.4$ bash-4.4$ cd user/platform/ bash-4.4$ bash-4.4$ git pull remote: Enumerating objects: 15, done. remote: Counting objects: 100% (15/15), done. remote: Compressing objects: 100% (8/8), done. remote: Total 13 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (13/13), done. From ../../remote/platform 7fad4be..ea52eab master -> origin/master Updating 7fad4be..ea52eab Fast-forward README | 2 +- build-system/README | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 build-system/README bash-4.4$ 

Además, los usuarios podrán seguir el historial de desarrollo no solo del repositorio principal del proyecto, sino también de todos sus subárboles:


 bash-4.4$ bash-4.4$ git log -3 --graph * commit ea52eabd5910159efabd80adcf522f22bf6a2af2 (HEAD -> master, origin/master, origin/HEAD) |\ Merge: 442c9e9 e5c5446 | | Author: user <___@_______> | | Date: Thu Nov 1 20:48:05 2018 +0300 | | | | Pull changes from master of upstream build-system.git repository. | | | | Merge commit 'e5c5446967599065dc02a269d8fcfc2c1d3c4f65' | | | * commit e5c5446967599065dc02a269d8fcfc2c1d3c4f65 | | Author: user <___@_______> | | Date: Thu Nov 1 20:26:52 2018 +0300 | | | | update build-system version to 1.0.1 | | * | commit 442c9e94c9890032fb2f3123661345d465e2849f | | Author: user <___@_______> | | Date: Thu Nov 1 20:41:40 2018 +0300 | | | | update platform version to 1.0.1 bash-4.4$ 


Entrega de cambios de subárbol al repositorio ascendente


Recuerde el estado de los archivos, así como el repositorio de la plataforma en sí:


 bash-4.4$ bash-4.4$ git log -3 --graph * commit ea52eabd5910159efabd80adcf522f22bf6a2af2 (HEAD -> master, origin/master, origin/HEAD) |\ Merge: 442c9e9 e5c5446 | | Author: user <___@_______> | | Date: Thu Nov 1 20:48:05 2018 +0300 | | | | Pull changes from master of upstream build-system.git repository. | | | | Merge commit 'e5c5446967599065dc02a269d8fcfc2c1d3c4f65' | | | * commit e5c5446967599065dc02a269d8fcfc2c1d3c4f65 | | Author: user <___@_______> | | Date: Thu Nov 1 20:26:52 2018 +0300 | | | | update build-system version to 1.0.1 | | * | commit 442c9e94c9890032fb2f3123661345d465e2849f | | Author: user <___@_______> | | Date: Thu Nov 1 20:41:40 2018 +0300 | | | | update platform version to 1.0.1 bash-4.4$ 

Haremos cambios en el subárbol del sistema de compilación . Para hacer esto, edite el archivo plataforma / build-system / README :


 bash-4.4$ bash-4.4$ cd owner/platform/ bash-4.4$ bash-4.4$ vim build-system/README bash-4.4$ cat build-system/README [master] build-system 1.0.2 bash-4.4$ bash-4.4$ git add build-system/README bash-4.4$ git commit -m "build-system is updated to version 1.0.2 from platform side" [master abaa2c5] build-system is updated to version 1.0.2 from platform side 1 file changed, 1 insertion(+), 1 deletion(-) bash-4.4$ 

Pero no registraremos estos cambios en el repositorio de la plataforma de origen / maestro. Es decir, no ejecutaremos el comando git-push (1) , sino que ejecutaremos git-subtree-push directamente en el origen del repositorio remoto / build-system.git :


 bash-4.4$ bash-4.4$ git subtree push --prefix=build-system ../../remote/build-system.git/ master git push using: ../../remote/build-system.git/ master Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Writing objects: 100% (3/3), 290 bytes | 290.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To ../../remote/build-system.git/ e5c5446..0673142 0673142942ccf53514a276e855a98514952bb713 -> master bash-4.4$ 

Desplácese por los subárboles y asegúrese de que las ramas maestras HEAD del repositorio remoto / build-system.git original continúen:


 bash-4.4$ bash-4.4$ git subtree -d --list Looking for externals... Commit: 47905bcb80be6f7cb3030513986fad4df548f812 build-system ../../remote/build-system.git/ branch master HEAD The 'build-system' subtree seems not updated: original revision: 783c6d5af1100e9665f930c818c861ff011bed19 remote revision: 0673142942ccf53514a276e855a98514952bb713 You can update 'build-system' subtree by following command: git subtree pull --prefix=build-system ../../remote/build-system.git/ master bash-4.4$ 

Además, veamos el estado de la copia local del repositorio de la plataforma , recordando que la última confirmación aún no la hemos configurado en el repositorio ascendente:


 bash-4.4$ bash-4.4$ git log -4 --graph * commit abaa2c5edd49dd0cf395c99877b4711d0170af37 (HEAD -> master) | Author: user <___@_______> | Date: Thu Nov 1 21:48:40 2018 +0300 | | build-system is updated to version 1.0.2 from platform side | * commit ea52eabd5910159efabd80adcf522f22bf6a2af2 (origin/master) |\ Merge: 442c9e9 e5c5446 | | Author: user <___@_______> | | Date: Thu Nov 1 20:48:05 2018 +0300 | | | | Pull changes from master of upstream build-system.git repository. | | | | Merge commit 'e5c5446967599065dc02a269d8fcfc2c1d3c4f65' | | | * commit e5c5446967599065dc02a269d8fcfc2c1d3c4f65 | | Author: user <___@_______> | | Date: Thu Nov 1 20:26:52 2018 +0300 | | | | update build-system version to 1.0.1 | | * | commit 442c9e94c9890032fb2f3123661345d465e2849f | | Author: user <___@_______> | | Date: Thu Nov 1 20:41:40 2018 +0300 | | | | update platform version to 1.0.1 bash-4.4$ 

La forma correcta de entregar cambios en el repositorio ascendente del proyecto principal es asegurarse de que todos nuestros cambios de subárbol no vayan directamente al repositorio principal, sino que provengan del repositorio ascendente del subárbol como si los estuviéramos recibiendo usando el comando git-subtree-pull . A continuación, explicaremos el significado de nuestras acciones, y ahora, para evitar problemas posteriores, revertiremos la última confirmación ( abaa2c5edd49dd0cf395c99877b4711d0170af37 ) a una copia local del repositorio de la plataforma :


 bash-4.4$ bash-4.4$ git reset --hard HEAD^ HEAD is now at ea52eab Pull changes from master of upstream build-system.git repository. bash-4.4$ 

para luego "eliminar" la misma confirmación, pero desde el repositorio original original / build-system.git upstream. Pero primero, asegúrese de haber eliminado la última confirmación abaa2c5edd49dd0cf395c99877b4711d0170af37 :


 bash-4.4$ bash-4.4$ git log -3 --graph * commit ea52eabd5910159efabd80adcf522f22bf6a2af2 (HEAD -> master, origin/master) |\ Merge: 442c9e9 e5c5446 | | Author: user <___@_______> | | Date: Thu Nov 1 20:48:05 2018 +0300 | | | | Pull changes from master of upstream build-system.git repository. | | | | Merge commit 'e5c5446967599065dc02a269d8fcfc2c1d3c4f65' | | | * commit e5c5446967599065dc02a269d8fcfc2c1d3c4f65 | | Author: user <___@_______> | | Date: Thu Nov 1 20:26:52 2018 +0300 | | | | update build-system version to 1.0.1 | | * | commit 442c9e94c9890032fb2f3123661345d465e2849f | | Author: user <___@_______> | | Date: Thu Nov 1 20:41:40 2018 +0300 | | | | update platform version to 1.0.1 bash-4.4$ 

, ea52eabd5910159efabd80adcf522f22bf6a2af2 , remote/build-system.git . , , git-subtree-pull :


 bash-4.4$ bash-4.4$ git subtree pull --prefix=build-system ../../remote/build-system.git/ master From ../../remote/build-system * branch master -> FETCH_HEAD hint: Waiting for your editor to close the file... 

, :


Merge commit '0673142942ccf53514a276e855a98514952bb713'

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
# #
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.

:


Pull changes from master of origin remote/build-system repository.

Merge commit '0673142942ccf53514a276e855a98514952bb713'

, , :


 Merge made by the 'recursive' strategy. build-system/README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) bash-4.4$ 

, , remote/build-system.git - . , build-system platform , remote/build-system.git :


 bash-4.4$ bash-4.4$ git log --graph * commit 04a13bac91d1c445994ffc19db8b479d5e644e17 (HEAD -> master) |\ Merge: ea52eab 0673142 | | Author: user <___@_______> | | Date: Thu Nov 1 21:59:45 2018 +0300 | | | | Pull changes from master of origin remote/build-system repository. | | | | Merge commit '0673142942ccf53514a276e855a98514952bb713' | | | * commit 0673142942ccf53514a276e855a98514952bb713 | | Author: user <___@_______> | | Date: Thu Nov 1 21:48:40 2018 +0300 | | | | build-system is updated to version 1.0.2 from platform side | | * | commit ea52eabd5910159efabd80adcf522f22bf6a2af2 (origin/master) |\ \ Merge: 442c9e9 e5c5446 | |/ Author: user <___@_______> | | Date: Thu Nov 1 20:48:05 2018 +0300 | | | | Pull changes from master of upstream build-system.git repository. | | | | Merge commit 'e5c5446967599065dc02a269d8fcfc2c1d3c4f65' | | | * commit e5c5446967599065dc02a269d8fcfc2c1d3c4f65 | | Author: user <___@_______> | | Date: Thu Nov 1 20:26:52 2018 +0300 | | | | update build-system version to 1.0.1 | | * | commit 442c9e94c9890032fb2f3123661345d465e2849f | | Author: user <___@_______> | | Date: Thu Nov 1 20:41:40 2018 +0300 | | | | update platform version to 1.0.1 | | * | commit 47905bcb80be6f7cb3030513986fad4df548f812 |\ \ Merge: 7fad4be 783c6d5 | |/ Author: user <___@_______> | | Date: Thu Nov 1 20:20:20 2018 +0300 | | | | Add 'build-system/' from commit '783c6d5af1100e9665f930c818c861ff011bed19' | | | | git-subtree-dir: build-system | | git-subtree-mainline: 7fad4becbd13258216fb95cbe9d987dd33f0be6d | | git-subtree-split: 783c6d5af1100e9665f930c818c861ff011bed19 | | git-subtree-repo: ../../remote/build-system.git/ | | git-subtree-ref: master | | | * commit 783c6d5af1100e9665f930c818c861ff011bed19 | Author: user <___@_______> | Date: Thu Nov 1 20:16:33 2018 +0300 | | init build-system master 1.0.0 | * commit 7fad4becbd13258216fb95cbe9d987dd33f0be6d Author: user <___@_______> Date: Thu Nov 1 20:16:33 2018 +0300 init platform master 1.0.0 bash-4.4$ 

, , upstream- remote/platform.git .


 bash-4.4$ bash-4.4$ git status On branch master Your branch is ahead of 'origin/master' by 2 commits. (use "git push" to publish your local commits) nothing to commit, working tree clean bash-4.4$ bash-4.4$ git push Enumerating objects: 9, done. Counting objects: 100% (8/8), done. Delta compression using up to 4 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (5/5), 600 bytes | 600.00 KiB/s, done. Total 5 (delta 0), reused 0 (delta 0) To ../../remote/platform.git ea52eab..04a13ba master -> master bash-4.4$ 

, git-subtree-pull , . , git-push(1) , , , .


, upstream- remote/platform.git 04a13bac91d1c445994ffc19db8b479d5e644e17 , remote/build-system.git , , git-subtree-pull , upstream- remote/platform.git , upstream- remote/platform.git (owner/platform).



git-format-patch


, , git-subtre ,
:


  git log -- . ":(exclude)build-system" git log -- build-system 

, , .


git-format-patch .


, , patch- ea52eabd5910159efabd80adcf522f22bf6a2af2 , git-format-patch :


 bash-4.4$ bash-4.4$ git format-patch ea52eabd5910159efabd80adcf522f22bf6a2af2 --stdout From 0673142942ccf53514a276e855a98514952bb713 Mon Sep 17 00:00:00 2001 From: user <___@_______> Date: Thu, 1 Nov 2018 21:48:40 +0300 Subject: [PATCH] build-system is updated to version 1.0.2 from platform side --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index 629b3f4..4fbbbaf 100644 --- a/README +++ b/README @@ -1,3 +1,3 @@ -[master] build-system 1.0.1 +[master] build-system 1.0.2 -- 2.19.1 bash-4.4$ 

, build-system/README build-system/, :


 --- a/README +++ b/README 

,
git-diff :


 bash-4.4$ bash-4.4$ git diff ea52eabd5910159efabd80adcf522f22bf6a2af2 04a13bac91d1c445994ffc19db8b479d5e644e17 diff --git a/build-system/README b/build-system/README index 629b3f4..4fbbbaf 100644 --- a/build-system/README +++ b/build-system/README @@ -1,3 +1,3 @@ -[master] build-system 1.0.1 +[master] build-system 1.0.2 bash-4.4$ 

patch-:


 --- a/build-system/README +++ b/build-system/README 

git-diff(1) , , , platform .



Políticos


CM- , . , , :


  • upstream- ;
  • upstream-, .

, .


, , upstream- remote/build-system.git :


 bash-4.4$ bash-4.4$ cd owner/build-system/ bash-4.4$ cat README [master] build-system 1.0.2 bash-4.4$ 

, upstream- remote/build-system.git , , , minor 1.0.2 . build-system-1.1.x , , : 1.1.0 , 1.1.1 , 1.1.2 , .


:


 bash-4.4$ bash-4.4$ git checkout -b build-system-1.1.x Switched to a new branch 'build-system-1.1.x' bash-4.4$ git branch * build-system-1.1.x master bash-4.4$ 

, README 1.1.0 :


 bash-4.4$ bash-4.4$ vim README bash-4.4$ cat README [master] build-system 1.1.0 bash-4.4$ bash-4.4$ git commit -a -m "Move on to developing 1.1.x functionality" [build-system-1.1.x f6d79c1] Move on to developing 1.1.x functionality 1 file changed, 1 insertion(+), 1 deletion(-) bash-4.4$ 

upstream- remote/build-system.git :


 bash-4.4$ bash-4.4$ git push --set-upstream origin build-system-1.1.x Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Writing objects: 100% (3/3), 280 bytes | 280.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To ../../remote/build-system.git * [new branch] build-system-1.1.x -> build-system-1.1.x Branch 'build-system-1.1.x' set up to track remote branch 'build-system-1.1.x' from 'origin'. bash-4.4$ 

, , , 1.1.1 :


 bash-4.4$ bash-4.4$ vim README bash-4.4$ cat README [master] build-system 1.1.1 bash-4.4$ bash-4.4$ git commit -a -m "Update build-system version to 1.1.1" [build-system-1.1.x f9544a4] Update build-system version to 1.1.1 1 file changed, 1 insertion(+), 1 deletion(-) bash-4.4$ bash-4.4$ git push Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Writing objects: 100% (3/3), 276 bytes | 276.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To ../../remote/build-system.git f6d79c1..f9544a4 build-system-1.1.x -> build-system-1.1.x bash-4.4$ 

:


 bash-4.4$ bash-4.4$ git tag -a 1.1.1 -m "Created tag for release (version 1.1.1)" bash-4.4$ git push origin 1.1.1 Enumerating objects: 1, done. Counting objects: 100% (1/1), done. Writing objects: 100% (1/1), 170 bytes | 170.00 KiB/s, done. Total 1 (delta 0), reused 0 (delta 0) To ../../remote/build-system.git * [new tag] 1.1.1 -> 1.1.1 bash-4.4$ 

upstream- remote/build-system.git :


 bash-4.4$ bash-4.4$ cd remote/build-system.git/ bash-4.4$ tree refs refs ├── heads │  ├── build-system-1.1.x │  └── master └── tags └── 1.1.1 2 directories, 3 files bash-4.4$ 

, platform build-system . , , , , platform-1.0.2 :


 bash-4.4$ bash-4.4$ cd user/platform/ bash-4.4$ git branch * master bash-4.4$ git pull Already up to date. bash-4.4$ bash-4.4$ git checkout -b platform-1.0.2 Switched to a new branch 'platform-1.0.2' bash-4.4$ vim README bash-4.4$ cat README [master] platform 1.0.2 bash-4.4$ git commit -a -m "reated platform-1.0.2 branch for the transition to the system 1.1.1" [platform-1.0.2 00a1250] reated platform-1.0.2 branch for the transition to the system 1.1.1 1 file changed, 1 insertion(+), 1 deletion(-) bash-4.4$ 

, , - remote/build-system.git , 1.1.1 :


 bash-4.4$ bash-4.4$ git rm -rf build-system/ rm 'build-system/README' bash-4.4$ git commit -a -m "Removed subtre based on build-system/master" [platform-1.0.2 7db0f54] Removed subtre based on build-system/master 1 file changed, 3 deletions(-) delete mode 100644 build-system/README bash-4.4$ bash-4.4$ bash-4.4$ git push --set-upstream origin platform-1.0.2 Enumerating objects: 7, done. Counting objects: 100% (7/7), done. Delta compression using up to 4 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (5/5), 550 bytes | 550.00 KiB/s, done. Total 5 (delta 0), reused 0 (delta 0) To ../../remote/platform.git/ * [new branch] platform-1.0.2 -> platform-1.0.2 Branch 'platform-1.0.2' set up to track remote branch 'platform-1.0.2' from 'origin'. bash-4.4$ bash-4.4$ bash-4.4$ git subtree add --prefix=build-system ../../remote/build-system.git/ 1.1.1 git fetch ../../remote/build-system.git/ 1.1.1 remote: Enumerating objects: 9, done. remote: Counting objects: 100% (9/9), done. remote: Compressing objects: 100% (3/3), done. remote: Total 7 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (7/7), done. From ../../remote/build-system * tag 1.1.1 -> FETCH_HEAD Added dir 'build-system' bash-4.4$ 

build-system upstream- remote/platform.git :


 bash-4.4$ bash-4.4$ git push Enumerating objects: 12, done. Counting objects: 100% (12/12), done. Delta compression using up to 4 threads Compressing objects: 100% (4/4), done. Writing objects: 100% (8/8), 889 bytes | 889.00 KiB/s, done. Total 8 (delta 0), reused 0 (delta 0) To ../../remote/platform.git/ 7db0f54..6f1a50e platform-1.0.2 -> platform-1.0.2 bash-4.4$ 

:


 bash-4.4$ bash-4.4$ git log -3 --graph * commit 6f1a50e249e01f69c54f343b65747d28abc6456d (HEAD -> platform-1.0.2, origin/platform-1.0.2) |\ Merge: 7db0f54 f9544a4 | | Author: user <___@_______> | | Date: Fri Nov 2 18:24:54 2018 +0300 | | | | Add 'build-system/' from commit 'f045926542e9f685034545a45317093383fddf99' | | | | git-subtree-dir: build-system | | git-subtree-mainline: 7db0f5452e67086dc4e381a0ccb14f25d48ecf0b | | git-subtree-split: f045926542e9f685034545a45317093383fddf99 | | git-subtree-repo: ../../remote/build-system.git/ | | git-subtree-ref: 1.1.1 | | | * commit f9544a4cc2650a83b96f400fdfc95ba64a38ec6e | | Author: user <___@_______> | | Date: Fri Nov 2 17:59:43 2018 +0300 | | | | Update build-system version to 1.1.1 | | | * commit f6d79c12ada29438454739fe6f6db9592d413be2 | | Author: user <___@_______> | | Date: Fri Nov 2 17:54:35 2018 +0300 | | | | Move on to developing 1.1.x functionality bash-4.4$ 

, CM- , platform , platform-1.0.2 build-system . , , build-system , .


, upstream- build-system platform , pre-receive


  remote/build-system.git/hooks/pre-receive 

, , :


 #!/bin/sh zero_commit="0000000000000000000000000000000000000000" LC_COLLATE='C' allowed_users=(habr habrahabr) while read oldrev newrev refname; do # # git-subtree(1) push       , #    .      # : # # 1)       ,   ,  # 2)         tag,    #       ,  , , #  'refs/tags/1.1.1',  '1.1.1',  git-subtree(1) #       'refs/heads/1.1.1', #     . # : if [[ $oldrev == $zero_commit && $refname =~ ^refs/heads/ ]]; then refbase=$(basename $refname) refpath=$(git show-ref $refbase | cut -f2 -d' ') if [[ $refpath =~ ^refs/tags/.*$ ]]; then echo "" echo "ERROR: Trying to change TAG named as '$refpath'." echo "" exit 1 fi if [[ ! ${allowed_users[*]} =~ $USER ]]; then echo "" echo "ERROR: Trying to create NEW BRANCH with name '$refname'." echo "" exit 1 fi fi done exit 0 

. , , , , , , . , , :


  git subtree push --prefix=<subdir> <remote> <ref> 

<ref> , <subdir> , , (refs/tags/1.1.1), (1.1.1) upstream- ( : refs/heads/1.1.1).


, git-subtree(1) . .


, pre-receive , user/platform/build-system/README:


 bash-4.4$ bash-4.4$ cd user/platform/ bash-4.4$ vim build-system/README bash-4.4$ cat build-system/README [master] build-system 1.1.1 Try to change. bash-4.4$ bash-4.4$ git commit -a -m "Try to change the tag of build-system" [platform-1.0.2 34e7970] Try to change the tag of build-system 1 file changed, 2 insertions(+) bash-4.4$ 

upstream- remote/build-system.git .


...

upstream-


  git subtree push --prefix=<subdir> <remote> <ref> 

, , , :


 bash-4.4$ git subtree -d --list Looking for externals... Commit: 6f1a50e249e01f69c54f343b65747d28abc6456d build-system ../../remote/build-system.git/ tag 1.1.1 f045926542e9f685034545a45317093383fddf99 bash-4.4$ 

, , upstream- remote/build-system.git :




 bash-4.4$ bash-4.4$ git subtree push --prefix=build-system ../../remote/build-system.git/ 1.1.1 git push using: ../../remote/build-system.git/ 1.1.1 Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Writing objects: 100% (3/3), 293 bytes | 293.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) remote: remote: ERROR: Trying to change TAG named as 'refs/tags/1.1.1'. remote: To ../../remote/build-system.git/ ! [remote rejected] c3a7333aaa818a7d7a0d501d4b69db1c6a01d40f -> 1.1.1 (pre-receive hook declined) error: failed to push some refs to '../../remote/build-system.git/' bash-4.4$ 

, , pre-receive , . :


 remote: remote: ERROR: Trying to change TAG named as 'refs/tags/1.1.1'. remote: 

, , , , :


 bash-4.4$ bash-4.4$ git reset --hard HEAD^ HEAD is now at 6f1a50e Add 'build-system/' from commit 'f045926542e9f685034545a45317093383fddf99' bash-4.4$ 

, , platform-1.0.2 :


 bash-4.4$ bash-4.4$ git log -3 --graph * commit 6f1a50e249e01f69c54f343b65747d28abc6456d (HEAD -> platform-1.0.2, origin/platform-1.0.2) |\ Merge: 7db0f54 f9544a4 | | Author: user <___@_______> | | Date: Fri Nov 2 18:24:54 2018 +0300 | | | | Add 'build-system/' from commit 'f045926542e9f685034545a45317093383fddf99' | | | | git-subtree-dir: build-system | | git-subtree-mainline: 7db0f5452e67086dc4e381a0ccb14f25d48ecf0b | | git-subtree-split: f045926542e9f685034545a45317093383fddf99 | | git-subtree-repo: ../../remote/build-system.git/ | | git-subtree-ref: 1.1.1 | | | * commit f9544a4cc2650a83b96f400fdfc95ba64a38ec6e | | Author: user <___@_______> | | Date: Fri Nov 2 17:59:43 2018 +0300 | | | | Update build-system version to 1.1.1 | | | * commit f6d79c12ada29438454739fe6f6db9592d413be2 | | Author: user <___@_______> | | Date: Fri Nov 2 17:54:35 2018 +0300 | | | | Move on to developing 1.1.x functionality bash-4.4$ 



git-subrepo , , squashed-, git-subtree(1) , .


, . git-subrepo . , git-subtree , , Git , , , Git .



:


Source: https://habr.com/ru/post/es429014/


All Articles