Muestra las diferencias entre dos versiones de la página.
Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa Última revisión Ambos lados, revisión siguiente | ||
clase:daw:daw:2eval:tema06 [2021/11/14 12:45] admin [Merge] |
clase:daw:daw:2eval:tema06 [2023/12/11 10:33] admin [Usando Ramas] |
||
---|---|---|---|
Línea 14: | Línea 14: | ||
{{: | {{: | ||
+ | {{: | ||
Ejemplo de Ramas | Ejemplo de Ramas | ||
Línea 50: | Línea 51: | ||
* Crear una rama nueva y subirla | * Crear una rama nueva y subirla | ||
+ | <sxh bash> | ||
git branch nuevaRama | git branch nuevaRama | ||
- | git checkout | + | git switch |
- | git push -u origin | + | git push origin |
+ | </ | ||
\\ | \\ | ||
\\ | \\ | ||
* Bajar una nueva rama | * Bajar una nueva rama | ||
+ | <sxh bash> | ||
git fetch --prune | git fetch --prune | ||
- | git checkout | + | git switch |
+ | </ | ||
<note tip> | <note tip> | ||
* '' | * '' | ||
- | * '' | + | * '' |
</ | </ | ||
Línea 71: | Línea 76: | ||
* Borrar una rama en local que ha sido mergeada o subida | * Borrar una rama en local que ha sido mergeada o subida | ||
+ | <sxh bash> | ||
git branch -d miRama | git branch -d miRama | ||
git branch --delete miRama | git branch --delete miRama | ||
+ | </ | ||
\\ | \\ | ||
Línea 79: | Línea 86: | ||
* Borrar una rama en local que NO ha sido mergeada ni subida (hay 3 formas distintas). Pero es usar el modificador '' | * Borrar una rama en local que NO ha sido mergeada ni subida (hay 3 formas distintas). Pero es usar el modificador '' | ||
+ | <sxh bash> | ||
git branch -d -f miRama | git branch -d -f miRama | ||
git branch --delete --force miRama | git branch --delete --force miRama | ||
git branch -D | git branch -D | ||
+ | </ | ||
Línea 89: | Línea 98: | ||
* Borrar una rama en remoto | * Borrar una rama en remoto | ||
+ | <sxh bash> | ||
git push origin --delete miRama | git push origin --delete miRama | ||
+ | </ | ||
\\ | \\ | ||
Línea 114: | Línea 125: | ||
Se usa para poner los commits de origin/ | Se usa para poner los commits de origin/ | ||
- | |||
{{: | {{: | ||
+ | |||
+ | |||
+ | '' | ||
+ | < | ||
+ | %%{init: { ' | ||
+ | gitGraph | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | |||
+ | </ | ||
\\ | \\ | ||
+ | '' | ||
+ | < | ||
+ | %%{init: { ' | ||
+ | gitGraph | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | '' | ||
+ | \\ | ||
+ | '' | ||
+ | < | ||
+ | %%{init: { ' | ||
+ | gitGraph | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | |||
+ | </ | ||
==== git merge --squash rama ==== | ==== git merge --squash rama ==== | ||
Línea 137: | Línea 192: | ||
\\ | \\ | ||
+ | |||
+ | < | ||
+ | %%{init: { ' | ||
+ | gitGraph | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | '' | ||
+ | < | ||
+ | %%{init: { ' | ||
+ | gitGraph | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | |||
+ | |||
+ | \\ | ||
+ | '' | ||
+ | < | ||
+ | %%{init: { ' | ||
+ | gitGraph | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | |||
==== git merge rama ==== | ==== git merge rama ==== | ||
Línea 150: | Línea 243: | ||
* Bajar (o actualizar) una rama ( como master, release o develop) desde Github, | * Bajar (o actualizar) una rama ( como master, release o develop) desde Github, | ||
+ | <sxh bash> | ||
git fetch --prune | git fetch --prune | ||
- | git checkout | + | git switch |
git merge --ff-only origin/ | git merge --ff-only origin/ | ||
git fetch --prune | git fetch --prune | ||
- | git checkout | + | git switch |
git merge --ff-only origin/ | git merge --ff-only origin/ | ||
git fetch --prune | git fetch --prune | ||
- | git checkout | + | git switch |
git merge --ff-only origin/ | git merge --ff-only origin/ | ||
+ | </ | ||
\\ | \\ | ||
Línea 168: | Línea 263: | ||
* mergear , develop en release o release en master (suponiendo que están actualizadas ambas ramas porque las hemos actualizado con las órdenes anteriores) y que no hemos hecho commits directamente ni en release ni en master. | * mergear , develop en release o release en master (suponiendo que están actualizadas ambas ramas porque las hemos actualizado con las órdenes anteriores) y que no hemos hecho commits directamente ni en release ni en master. | ||
- | | + | <sxh bash> |
+ | | ||
git merge --ff-only develop | git merge --ff-only develop | ||
- | git checkout | + | git switch |
git merge --ff-only release | git merge --ff-only release | ||
+ | </ | ||
\\ | \\ | ||
Línea 180: | Línea 277: | ||
* Mergear (rebase) los cambios de origin/ | * Mergear (rebase) los cambios de origin/ | ||
+ | <sxh bash> | ||
git fetch --prune | git fetch --prune | ||
- | git checkout | + | git switch |
git rebase origin/ | git rebase origin/ | ||
+ | </ | ||
- | Lo normal es hacer el rebase cuando al hacer un '' | + | Lo normal es hacer el rebase cuando al hacer un '' |
! [rejected] | ! [rejected] | ||
Línea 201: | Línea 300: | ||
- | | + | <sxh bash> |
+ | | ||
git merge --squash lorenzo_42 | git merge --squash lorenzo_42 | ||
git commit -am " | git commit -am " | ||
+ | </ | ||
< | < | ||
Línea 213: | Línea 314: | ||
* Mergear | * Mergear | ||
- | | + | <sxh bash> |
+ | | ||
git merge develop | git merge develop | ||
+ | </ | ||
\\ | \\ | ||
\\ | \\ | ||
Línea 238: | Línea 341: | ||
Es decir que avisa que se configure para saber que hacer en caso de problemas, si con Fast-Forward, | Es decir que avisa que se configure para saber que hacer en caso de problemas, si con Fast-Forward, | ||
+ | <sxh bash> | ||
git config --global pull.ff only | git config --global pull.ff only | ||
+ | </ | ||
De esa forma podremos hacer un '' | De esa forma podremos hacer un '' | ||
Línea 264: | Línea 369: | ||
En caso de hacer un '' | En caso de hacer un '' | ||
- | ==== Conflicto en merge ==== | + | Imaginemos |
- | Imaginemos | + | |
- | | + | ^ Nuestra Rama |
- | git merge --squash feature_lorenzo_45 | + | | <sxh html> |
- | + | < | |
- | Si hay un conflicto se producirá el siguiente mensaje: | + | < |
- | + | < | |
- | | + | </ |
- | | + | </html> |
- | | + | </ |
- | | + | < |
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
- | En ese caso deberemos editar el fichero '' | + | Cuando se produce |
+ | <sxh Diff> | ||
< | < | ||
< | < | ||
Línea 285: | Línea 395: | ||
======= | ======= | ||
< | < | ||
- | >>>>>>> | + | >>>>>>> |
</ | </ | ||
</ | </ | ||
+ | </ | ||
- | Ahí se indica las lineas que debemos unificar.Y para arreglarlo hay eliminar las líneas que delimitan el conflicto.Que dando por ejemplo así: | ||
- | < | + | Ahora tenemos que decidir como resolver el conflicto que el resultado definitivo ya depende del código que estemos fusionando. Un posible resultado podría ser: |
- | < | + | |
- | < | + | |
- | </ | + | |
- | </ | + | |
- | y finalmente hacer el '' | + | <sxh html> |
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
- | git commit -am " | ||
- | + | ==== | |
- | ==== Conflicto en rebase ==== | + | |
Imaginemos que queremos mergear la rama '' | Imaginemos que queremos mergear la rama '' | ||
- | |||
- | git checkout develop | ||
- | git rebase origin/ | ||
Si hay un conflicto se producirá el siguiente mensaje: | Si hay un conflicto se producirá el siguiente mensaje: | ||
Línea 328: | Línea 435: | ||
Ahora debemos como antes arreglar el conflicto editando el fichero '' | Ahora debemos como antes arreglar el conflicto editando el fichero '' | ||
+ | <sxh bash> | ||
git add index.html | git add index.html | ||
git rebase --continue | git rebase --continue | ||
+ | </ | ||
| | ||
Es decir añadir el fichero que ha dado el conflicto con un '' | Es decir añadir el fichero que ha dado el conflicto con un '' | ||
- | + | El ejemplo completo lo podemos ver aquí: | |
- | El ejemplo completo lo podemos ver aqui: | + | |
<sxh bash> | <sxh bash> | ||
- | #Subimos los cambios de develop | + | git switch |
- | git push | + | |
- | #SI da algún problema, bajamos los cambios | + | |
- | git fetch --prune | + | |
- | git checkout | + | |
git rebase origin/ | git rebase origin/ | ||
- | #SI hay algún conflicto lo resolvemos | + | vi index.html |
- | vi ficheroN_del_conflicto | + | git add index.html |
- | #Es necesario hacer el git add para añadir los ficheros modificados por el conflicto | + | |
- | git add ficheroN_del_conflicto | + | |
- | # | + | |
git rebase --continue | git rebase --continue | ||
- | #Y finalmente ya podemos subirlos | ||
- | git push | ||
</ | </ | ||
\\ | \\ | ||
- | * Y para acabar un ejemplo para hacer un commit , mergearlos a las otras 2 ramas y subirlo | + | ==== git merge --squash rama ==== |
+ | Imaginemos que queremos mergear una rama de una funcionalidad llamada " | ||
+ | |||
+ | Si hay un conflicto se producirá el siguiente mensaje: | ||
+ | |||
+ | Auto-fusionando index.html | ||
+ | CONFLICTO (contenido): | ||
+ | Commit de squash -- no actualizando HEAD | ||
+ | Fusión automática falló; arregle los conflictos y luego realice un commit con el resultado. | ||
+ | |||
+ | Ahora debemos como antes arreglar el conflicto editando el fichero '' | ||
<sxh bash> | <sxh bash> | ||
- | #Bajarte la última versión de todo | + | |
- | git fetch --prune && git checkout develop && git merge --ff-only origin/ | + | |
</ | </ | ||
+ | | ||
+ | |||
+ | El ejemplo completo lo podemos ver aqui: | ||
+ | |||
<sxh bash> | <sxh bash> | ||
- | #Hacer el commit | + | git switch develop |
- | git commit -am " | + | git merge --squash Lorenzo_3 |
- | </ | + | vi index.html |
- | <sxh bash> | + | git commit -am " |
- | #Hacer los merges con las otras 2 ramas | + | |
- | git checkout release && | + | |
- | </ | + | |
- | <sxh bash> | + | |
- | #Subir los cambios de las 3 ramas | + | |
- | git checkout master && git push && git checkout release && git push && git checkout develop && git push | + | |
</ | </ | ||
+ | \\ | ||
- | ===== Mas cosas de Git ===== | + | ==== git merge --ff-only rama ==== |
- | Para acabar dejamos alguna pincelada mas de cosas que existen | + | Con un fast-forward nunca se puede producir un conflicto. |
+ | |||
+ | |||
+ | ==== git merge rama ==== | ||
+ | Imaginemos | ||
+ | |||
+ | |||
+ | Si hay un conflicto se producirá el siguiente mensaje: | ||
- | * fixup y autosquash: https:// | ||
<sxh base> | <sxh base> | ||
- | git commit | + | Auto-fusionando index.html |
- | git rebase -i --autosquash | + | CONFLICTO (contenido): |
+ | Fusión automática falló; arregle los conflictos y luego realice un commit | ||
</ | </ | ||
- | |||
- | * Stash | + | Ahora debemos como antes arreglar el conflicto editando el fichero '' |
- | < | + | |
- | git stash | + | < |
- | git stash pop | + | git add index.html |
+ | git merge --continue | ||
</ | </ | ||
+ | | ||
+ | Es decir añadir el fichero que ha dado el conflicto con un '' | ||
- | * Cherry-pick | ||
- | ==== Recetas ==== | + | El ejemplo completo lo podemos ver aqui: |
+ | |||
+ | <sxh bash> | ||
+ | git switch Lorenzo_3 | ||
+ | git merge develop | ||
+ | vi index.html | ||
+ | git add index.html | ||
+ | git merge --continue | ||
+ | </ | ||
+ | \\ | ||
+ | |||
+ | |||
+ | ===== Recetas | ||
* Bajarse lo último de las 3 ramas. | * Bajarse lo último de las 3 ramas. | ||
- | < | + | < |
- | git fetch --prune && git checkout | + | git fetch --prune && git switch |
</ | </ | ||
* Hacer un merge de las 3 ramas | * Hacer un merge de las 3 ramas | ||
- | < | + | < |
- | git checkout | + | git switch |
</ | </ | ||
* Subir las 3 ramas | * Subir las 3 ramas | ||
- | < | + | < |
- | git checkout | + | git switch |
</ | </ | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||