2010-01-23 19 views
6

Quiero usar combinaciones de subárbol para llevar un proyecto remoto a un directorio en mi propio árbol de git. Seguí las instrucciones aquí: using subtree mergeEtiquetas del subárbol de Git

Pero no estoy seguro de cómo pagar una etiqueta. Me imagino que esta es una solicitud común: desea incorporar un proyecto externo pero obtener una versión etiquetada segura de la fuente. La solución de combinación de subárbol funciona muy bien, pero no estoy seguro de cómo obtener la etiqueta que quiero. Amor git, pero a veces me duele la cabeza ...

Respuesta

3

Al escribir git tag obtendrá la lista de todas las etiquetas en su repositorio. Las etiquetas remotas también se muestran aquí, y no sé si pueden entrar en conflicto (no lo verificaron), y cómo verificar qué etiquetas se importaron a su repositorio.

Pero lo que he comprobado es que cuando agrega un control remoto y obtiene de otro proyecto, puede ver qué etiquetas se importan. Entonces puede fusionar con esa etiqueta, por ejemplo:

git merge -s ours --no-commit v0.1.2 # instead of: Bproject/master (2) 
git read-tree --prefix=dir-B/ -u v0.1.2 # instead of: Bproject/master (3) 

y debería funcionar.

espero que ayude un poco, pero no estoy tan avanzado con git como me gustaría :-)

+0

Si no proporciono Bproject/maestro, ¿Cómo sabe lo que git remoto Estoy fusión con? – cmaughan

+0

@cmaughan Git no sabe. Todo lo que sabe son sha y cada sha (representado también por tag, o Bproject/master) hace referencia a algún commit, que tiene padres, y así sucesivamente. Es por eso que buscas (opción '-f' en' git remote') los cambios del repositorio remoto, obtienes todos los commits y sus sha's. Y luego fusionas un árbol (remoto, por supuesto, por supuesto) con tu árbol. Espero que así sea como funciona – MBO

+0

Bien - ¡me suena bien! Lo de las etiquetas de colisión es algo que me he estado preguntando, si tengo una etiqueta, v1.5 en mi aplicación y el control remoto como una etiqueta v1.5, ¿cómo lo soluciona? De cualquier manera, parece ser la solución que estaba buscando ... – cmaughan

0

lo hice por un proyecto de ejemplo en Github que se llama hesco/hesco-weave de la siguiente manera:

solía rizo, jq, cortar y comandos de la cola en los siguientes ejemplos, por lo que es necesario tener antes de ejecutar los ejemplos.

Primera, las dos últimas etiquetas del proyecto se encuentran:

[email protected]: ~ $ curl -s https://api.github.com/repos/hesco/hesco-weave/git/refs/tags | jq -r ".[].ref" | cut -d "/" -f 3 
v0.1 
v0.2 
v0.3 
v0.4 
v0.5 
v0.6 
v0.7 
v0.8 
v0.8.6 
v0.8.7 

[email protected]: ~ $ curl -s https://api.github.com/repos/hesco/hesco-weave/git/refs/tags | jq -r ".[].ref" | cut -d "/" -f 3 | tail -n 3 
v0.8.6 
v0.8.7 

O si tiene una versión checkouted del proyecto:

[email protected]: ~/github/hesco-weave (master) $ git remote -v 
origin https://github.com/hesco/hesco-weave.git (fetch) 
origin https://github.com/hesco/hesco-weave.git (push) 
[email protected]: ~/github/hesco-weave (master) $ git tag -l 
v0.1 
v0.2 
v0.3 
v0.4 
v0.5 
v0.6 
v0.7 
v0.8 
v0.8.6 
v0.8.7 

[email protected]: ~/github/hesco-weave (master) $ git tag -l | tail -n 2 
v0.8.6 
v0.8.7 

el sha de referencias son las siguientes :

[email protected]: ~ $ git ls-remote | tail -n 2 
be74d8368acd4815b6863daded46a232944e0d84 refs/tags/v0.8.6 
9181306caa304b4cf8b3764b1446c0c4006833d8 refs/tags/v0.8.7 

En segundo lugar, se crea un repositorio git:

[email protected]: ~ $ mkdir -p ~/test 
[email protected]: ~ $ cd ~/test 
[email protected]: ~/test $ git init 
Initialized empty Git repository in ~/test/.git/ 
[email protected]: ~/test $ touch README.md 
[email protected]: ~/test $ git add . 
[email protected]: ~/test $ git commit -m "README.md added" 
[master (root-commit) b1ac90e] README.md added 
1 file changed, 0 insertions(+), 0 deletions(-) 
create mode 100644 README.md 
[email protected]: ~/test (master) $ git log 
commit 19c0570a414c4fd1635444b7a937dfc41c93a847 
Author: Me <[email protected]> 
Date: Wed Jun 14 13:02:05 2017 +0200 

README.md added 

Tercer, se añade la etiqueta v0.8.6 del repositorio del Github al repositorio creado como subárbol: información

[email protected]: ~/test (master) $ git subtree add --squash --prefix=weave https://github.com/hesco/hesco-weave.git v0.8.6 

git fetch https://github.com/hesco/hesco-weave.git v0.8.6 
warning: no common commits 
remote: Counting objects: 543, done. 
remote: Compressing objects: 100% (193/193), done. 
remote: Total 543 (delta 306), reused 536 (delta 306), pack-reused 0 
Receiving objects: 100% (543/543), 93.19 KiB | 0 bytes/s, done. 
Resolving deltas: 100% (306/306), done. 
From https://github.com/hesco/hesco-weave 
* tag    v0.8.6  -> FETCH_HEAD 
Added dir 'weave' 

Traza:

[email protected]: ~/test (master) $ git log 
commit e5dc318c4437cd22ebddb9e82e8c419aef72a781 
Merge: b1ac90e 19c0570 
Author: me <[email protected]> 
Date: Wed Jun 14 13:02:25 2017 +0200 

    Merge commit '19c0570a414c4fd1635444b7a937dfc41c93a847' as 'weave' 

commit 19c0570a414c4fd1635444b7a937dfc41c93a847 
Author: me <[email protected]> 
Date: Wed Jun 14 13:02:25 2017 +0200 

    Squashed 'weave/' content from commit be74d83 

    git-subtree-dir: weave 
    git-subtree-split: be74d8368acd4815b6863daded46a232944e0d84 

commit b1ac90efbfe5978bac52984c29e6ec7904ed9a75 
Author: me <[email protected]> 
Date: Wed Jun 14 13:02:05 2017 +0200 

    README.md added 

Finalmente, el subárbol de armadura con la nueva etiqueta v0.8.7 se fusionó con git subtree pull:

[email protected]: ~/test (master) $ git subtree pull --squash --prefix=weave https://github.com/hesco/hesco-weave.git v0.8.7 

warning: no common commits 
remote: Counting objects: 548, done. 
remote: Compressing objects: 100% (195/195), done. 
remote: Total 548 (delta 311), reused 541 (delta 309), pack-reused 0 
Receiving objects: 100% (548/548), 90.50 KiB | 0 bytes/s, done. 
Resolving deltas: 100% (311/311), done. 
From https://github.com/hesco/hesco-weave 
* tag    v0.8.7  -> FETCH_HEAD 
Merge made by the 'recursive' strategy. 
weave/Changelog  | 1 + 
weave/Modulefile | 2 +- 
weave/README.md  | 2 +- 
weave/metadata.json | 2 +- 
4 files changed, 4 insertions(+), 3 deletions(-) 

información Traza:

[email protected]: ~/test (master) $ git log 
commit 9116e133c8d84de1df9883a8b5558a2350ebc86e 
Merge: e5dc318 eb2e273 
Author: me <[email protected]> 
Date: Wed Jun 14 13:03:16 2017 +0200 

    Merge commit 'eb2e2733a75d59eb1adebf4755d5b11cb74e2b98' 

commit eb2e2733a75d59eb1adebf4755d5b11cb74e2b98 
Author: me <[email protected]> 
Date: Wed Jun 14 13:03:16 2017 +0200 

    Squashed 'weave/' changes from be74d83..9181306 

    9181306 make release used to update version to v0.8.7 
    3871cf5 Update changelog, tag v0.8.6, fix link in README 
    REVERT: be74d83 Update changelog, tag v0.8.6, fix link in README 

    git-subtree-dir: weave 
    git-subtree-split: 9181306caa304b4cf8b3764b1446c0c4006833d8 

commit e5dc318c4437cd22ebddb9e82e8c419aef72a781 
Merge: b1ac90e 19c0570 
Author: me <[email protected]> 
Date: Wed Jun 14 13:02:25 2017 +0200 

    Merge commit '19c0570a414c4fd1635444b7a937dfc41c93a847' as 'weave' 

commit 19c0570a414c4fd1635444b7a937dfc41c93a847 
Author: me <[email protected]> 
Date: Wed Jun 14 13:02:25 2017 +0200 

    Squashed 'weave/' content from commit be74d83 

    git-subtree-dir: weave 
    git-subtree-split: be74d8368acd4815b6863daded46a232944e0d84 

commit b1ac90efbfe5978bac52984c29e6ec7904ed9a75 
Author: me <[email protected]> 
Date: Wed Jun 14 13:02:05 2017 +0200 

    README.md added 


[email protected]: ~/test (master) $ ll 
total 4 
-rw-rw-r-- 1 me me 0 Jun 14 13:01 README.md 
drwxrwxr-x 8 me me 4096 Jun 14 13:03 weave 
Cuestiones relacionadas