This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
git [2018/06/03 11:50] admin |
git [2018/06/08 19:39] (current) admin |
||
---|---|---|---|
Line 32: | Line 32: | ||
===== Commit ===== | ===== Commit ===== | ||
>git commit -m 'Texto para el commit' | >git commit -m 'Texto para el commit' | ||
+ | Si no se especifica la opción -m se lanzará el editor por defecto para guardar en un fichero temporal el mensaje del commit. Con el flag -a se realizará commit de todos aquellos ficheros que estén siendo registrados, aunque no estén stageados | ||
+ | |||
===== Comprobar el estado de los ficheros ===== | ===== Comprobar el estado de los ficheros ===== | ||
>git status | >git status | ||
Line 194: | Line 196: | ||
>git difftool --staged | >git difftool --staged | ||
+ | ==== Borrado de ficheros ==== | ||
+ | |||
+ | Para borrar un fichero hay que quitarlo del staging y hacer commit | ||
+ | >rm PROJECTS.md | ||
+ | >git rm PROJECTS.md | ||
+ | >git commit | ||
+ | Si ya se había metido en el index lo que hay que hacer es utilizar el flag -f | ||
+ | Si lo que se quiere es eliminarlo del staging pero no del working tree, lo que hay que hacer es utilizar la opción --cached | ||
+ | |||
+ | ==== Visión de históricos ==== | ||
+ | |||
+ | >git log | ||
+ | >git log -p (lista diferencias entre commits) | ||
+ | >git log -2 (muestra únicamente los últimos dos) | ||
+ | >git log --pretty=oneline (muestra commits resumidos uno por línea) | ||
+ | >git log --pretty=format:"%h %s" --graph (muestra en formato de gráfico el historial de commits) | ||
+ | >git log --since=2.weeks (muestra los commits desde hace 2 commits. Funciona con --until y como valores fechas "2018-01-01" o "3 years 1 day 3 minutes ago". Los flags --author --grep. Por defecto son or. Si se quiere and hay que utilizar --all-match. -S muestra únicamente los commits que hay añadido o modificado esa cadena | ||
+ | |||
+ | ===== Undos ===== | ||
+ | >git commit --amend | ||
+ | Hace commit del staging area y modifica para ello el último commit. En caso de que no haya nada, lo único que hace es cambiar el mensaje de commit | ||
+ | |||
+ | Si lo que se quiere es quitar del staging un fichero, git status muestra cómo hacerlo | ||
+ | >git status | ||
+ | >git reset HEAD CONTRIBUTING.md | ||
+ | |||
+ | Para dejar el fichero como estaba tras el último commit lo que hay que hacer es lo siguiente: | ||
+ | >git checkout -- CONTRIBUTING.md | ||
+ | |||
+ | ===== Repositorios remotos ===== | ||
+ | >git remote | ||
+ | origin | ||
+ | | ||
+ | >git remote -v | ||
+ | origin https://gitlab.com/Aquiles1184/angular-tour-of-heroes.git (fetch) | ||
+ | origin https://gitlab.com/Aquiles1184/angular-tour-of-heroes.git (push) | ||
+ | |||
+ | Esto muestra todos los repositorios remotos configurados a los que se puede hacer push. Para añadir uno nuevo hay que utilizar el comando: | ||
+ | >git remote add minombre https://github.com/paulboone/ticgit | ||
+ | Esto añadirá las dos líneas del ejemplo anterior | ||
+ | |||
+ | Para descargar todos los cambios se realiza: | ||
+ | >git fetch nombre remoto | ||
+ | El comando clone automáticamente configura el master local para registrar la rama master remota en el servidor. | ||
+ | >git pull | ||
+ | descarga los datos y trata de hacer merge en la misma rama local | ||
+ | |||
+ | Para subir los cambios: | ||
+ | >git push origin master | ||
+ | Este comando sube la rama master al servidor apuntado por origin | ||
+ | |||
+ | |||
+ | Para ver informacion del repositorio remoto | ||
+ | >git remote show origin | ||
+ | * remote origin | ||
+ | Fetch URL: https://gitlab.com/Aquiles1184/angular-tour-of-heroes.git | ||
+ | Push URL: https://gitlab.com/Aquiles1184/angular-tour-of-heroes.git | ||
+ | HEAD branch: master | ||
+ | Remote branch: | ||
+ | master tracked | ||
+ | Local ref configured for 'git push': | ||
+ | master pushes to master (up to date) | ||
+ | |||
+ | Para renombrar un repositorio remoto la sintaxis es: | ||
+ | >git remote rename pb paul | ||
+ | |||
+ | Para borrar un repositorio remoto | ||
+ | >git remote rm paul | ||
+ | |||
+ | ===== Tags ===== | ||
+ | >git tag | ||
+ | Muestra todas las etiquetas del proyecto. También es posible buscar con caracteres comodín | ||
+ | >git tag -l "v1.8.5*" | ||
+ | |||
+ | ===== Branches ===== | ||
+ | Para crear un branch | ||
+ | >git checkout -b nombreBranch [tag] | ||
+ | Si [tag] tiene algo se creará un branch de ese tag. En caso contrario se creará un branch con lo que se tenga en ese momento en el working tree |