(→Borrando archivos y enmendando el último commit) |
|||
(No se muestran 25 ediciones intermedias de 2 usuarios) | |||
Línea 1: | Línea 1: | ||
+ | ==Documentación== | ||
+ | * Documentación oficial de Git: http://git-scm.com | ||
+ | * Libro ProGit (Creative Commons): http://git-scm.com/book | ||
+ | * Migración de repositorios SVN a GIT: http://viget.com/extend/effectively-using-git-with-subversion | ||
+ | * Artículos de Git en esta página: [[:Categoría:Git]] | ||
+ | |||
+ | ===Taller de Git=== | ||
+ | * [[Media:Taller de Git - Clase 1.pdf|Clase 1]] | ||
+ | * [[Media:Taller de Git - Clase 2.pdf|Clase 2]] | ||
+ | * [[Media:Taller de Git - Clase 3.pdf|Clase 3]] | ||
+ | |||
+ | ==Recetas== | ||
+ | ===Configuración=== | ||
* Configurar git para el usuario: | * Configurar git para el usuario: | ||
git config --global user.name "Pipo Perez" | git config --global user.name "Pipo Perez" | ||
Línea 4: | Línea 17: | ||
git config --global color.ui auto | git config --global color.ui auto | ||
git config --global core.editor vim | git config --global core.editor vim | ||
− | + | git config --global alias.lol 'log --graph --decorate --pretty=oneline --abbrev-commit' | |
+ | git config --global alias.lola 'log --graph --decorate --pretty=oneline --abbrev-commit --all --date=local' | ||
+ | git config --global alias.unstage 'reset HEAD --' | ||
[http://git-scm.com/book/ch7-1.html#Colors-in-Git Colores personalizados] | [http://git-scm.com/book/ch7-1.html#Colors-in-Git Colores personalizados] | ||
+ | ===Básicos=== | ||
* Inicializar un repositorio local | * Inicializar un repositorio local | ||
mkdir foobar | mkdir foobar | ||
Línea 23: | Línea 39: | ||
git commit -m "Comentario" | git commit -m "Comentario" | ||
+ | * Borrar archivos untracked | ||
+ | git clean -f | ||
+ | Para archivos untracked incluyendo los que estén en .gitignore: | ||
+ | git clean -f -x | ||
+ | |||
+ | ===Borrando archivos y enmendando el último commit=== | ||
+ | * Para sacar un archivo de el área de staging (si le hicimos "git add" por accidente): | ||
+ | git reset HEAD -- <archivo> | ||
+ | o si se definió el alias unstage como se ve arriba: | ||
+ | git unstage <archivo> | ||
+ | * Para deshacer los cambios de un archivo que no está commited: | ||
+ | git checkout -- <archivo> | ||
+ | * Para deshacer los cambios de todos los archivos que no está commited: | ||
+ | git checkout -- . | ||
+ | * Si faltó agregar o borrar algún archivo, o la descripción del último commit tiene errores: | ||
+ | git commit --amend | ||
+ | * Para corregir el nombre y dirección de autor del commiter: | ||
+ | git commit --amend --author "Nombre Apellido <napellido@email.com>" | ||
+ | * Para borrar un commit: | ||
+ | git reset --hard HEAD~1 | ||
+ | git push --force origin HEAD | ||
+ | |||
+ | * http://git-scm.com/book/en/Git-Basics-Undoing-Things | ||
+ | * http://stackoverflow.com/questions/1338728/how-to-delete-a-git-commit | ||
+ | |||
+ | ===Remotos=== | ||
* Agregando servidores remotos | * Agregando servidores remotos | ||
git remote add origin | git remote add origin | ||
Línea 35: | Línea 77: | ||
git push --set-upstream origin master | git push --set-upstream origin master | ||
git push -u origin master | git push -u origin master | ||
+ | |||
+ | ===Remotos con tags y branches=== | ||
+ | * Push de todos los branches (locales) y push de todos los tags: | ||
+ | git push --all | ||
+ | git push --tags | ||
+ | |||
+ | * Push de todas las refs (branches, tags y branches remotos): | ||
+ | git push --mirror | ||
+ | |||
+ | * Eliminar una ref en un remoto: | ||
+ | git push --delete nombre_branch | ||
+ | git push :nombre_branch | ||
+ | |||
+ | ===Diffs y logs=== | ||
+ | * Para comparar palabra a palabra cuando hay un conflicto y las líneas sean muy largas, primero debemos identificar los commit de los que se hicieron el merge, por ejemplo si uno es '''bba49bb''', y el otro '''834b27f''', el comando sería: | ||
+ | |||
+ | git diff --word-diff=color bba49bb 834b27f | ||
* Comparar con commits anteriores: | * Comparar con commits anteriores: | ||
− | |||
git diff HEAD~1 # Commit padre | git diff HEAD~1 # Commit padre | ||
− | git diff HEAD~2 # Commit | + | git diff HEAD~2 # Commit padre del commit padre |
+ | git diff HEAD^1 # Commit de un padre (para merges) | ||
+ | git diff HEAD^2 # Commit de otro padre (para merges) | ||
* Ver logs con dibujos de los branchs: | * Ver logs con dibujos de los branchs: | ||
Línea 50: | Línea 110: | ||
git whatchanged | git whatchanged | ||
+ | * Distintas formas de especificar una revisión: | ||
+ | http://git-scm.com/docs/gitrevisions.html | ||
+ | |||
+ | * Ver la historia de commits: | ||
+ | http://git-scm.com/book/en/Git-Basics-Viewing-the-Commit-History | ||
+ | |||
+ | ===Crear branches nuevos y vacíos=== | ||
+ | Por ejemplo pueden ser útiles para las gh-pages de GitHub: | ||
+ | <source lang="bash"> | ||
+ | git checkout --orphan NUEVO_BRANCH | ||
+ | git rm -rf . | ||
+ | </source> | ||
+ | |||
+ | * [http://bitflop.com/document/116 How to Create a New and Empty Branch in Git (bitflop.com)] | ||
+ | ===Eliminando archivos de la historia de Git (no hacer a menos que se justifique)=== | ||
+ | * https://help.github.com/articles/remove-sensitive-data | ||
+ | |||
+ | ===Reescribiendo la historia=== | ||
+ | Haciendo que la historia sea lineal, corrigiendo comentarios de commits, etc... | ||
+ | * http://git-scm.com/book/en/Git-Tools-Rewriting-History | ||
+ | |||
+ | Separar un directorio en un nuevo repositorio Git con git subtree y eliminar la historia de los archivos borrados: | ||
+ | * http://stackoverflow.com/questions/359424/detach-subdirectory-into-separate-git-repository/17864475 | ||
+ | en particular la [http://stackoverflow.com/questions/359424/detach-subdirectory-into-separate-git-repository/17864475#17864475 respuesta con título "The easy way"] | ||
[[Categoría:Git]] | [[Categoría:Git]] | ||
[[Categoría:Desarrollo]] | [[Categoría:Desarrollo]] |
git config --global user.name "Pipo Perez" git config --global user.email "pperez@servidor.com" # Un mail que se pueda publicar git config --global color.ui auto git config --global core.editor vim git config --global alias.lol 'log --graph --decorate --pretty=oneline --abbrev-commit' git config --global alias.lola 'log --graph --decorate --pretty=oneline --abbrev-commit --all --date=local' git config --global alias.unstage 'reset HEAD --'
mkdir foobar cd foobar git init
git add archivo git rm archivo
git add archivo
git status git commit -m "Comentario"
git clean -f
Para archivos untracked incluyendo los que estén en .gitignore:
git clean -f -x
git reset HEAD -- <archivo>
o si se definió el alias unstage como se ve arriba:
git unstage <archivo>
git checkout -- <archivo>
git checkout -- .
git commit --amend
git commit --amend --author "Nombre Apellido <napellido@email.com>"
git reset --hard HEAD~1 git push --force origin HEAD
git remote add origin
git push origin master
git pull origin master
git push --set-upstream origin master git push -u origin master
git push --all git push --tags
git push --mirror
git push --delete nombre_branch git push :nombre_branch
git diff --word-diff=color bba49bb 834b27f
git diff HEAD~1 # Commit padre git diff HEAD~2 # Commit padre del commit padre git diff HEAD^1 # Commit de un padre (para merges) git diff HEAD^2 # Commit de otro padre (para merges)
git log --graph --decorate
git blame archivo
git whatchanged
http://git-scm.com/docs/gitrevisions.html
http://git-scm.com/book/en/Git-Basics-Viewing-the-Commit-History
Por ejemplo pueden ser útiles para las gh-pages de GitHub:
git checkout --orphan NUEVO_BRANCH git rm -rf .
Haciendo que la historia sea lineal, corrigiendo comentarios de commits, etc...
Separar un directorio en un nuevo repositorio Git con git subtree y eliminar la historia de los archivos borrados:
en particular la respuesta con título "The easy way"