Aquesta és una revisió antiga del document
GIT
related
mate | |
mate | |
mate | |
mate | |
mate |
cheatsheet
doc
todo
git extras
https://github.com/tj/git-extras/- git-config condicional : https://www.kevinkuszyk.com/2018/12/10/git-tips-6-using-git-with-multiple-email-addresses/
config
- ubicación:
- system : /etc/gitconfig [–system]
- global : ~/.gitconfig [–global]
- repo : .git/config
git config --list --show-origin
git config [–global] –list
: si omitimos el ámbito, muestra todas las configuraciones disponiblesgit config –global user.name «Mi Nombre»
git config –global user.email «mi@email»
git config –global http.sslVerify false
: no verifica el certificado en peticiones por *https*git config –global core.editor «'$(which vim)'»
: asignar VIM como editor por defectogit config credential.helper store
: store contraseñas (texto plano) autenticacióngit config –global credential.helper 'cache --timeout 7200'
git config credential.helper libsecret
?
otros
errores
tips
- HEAD == @
- HEAD^ : commit anterior al HEAD
- HEAD@{1.month}
- - (guión) : te devuelve a la rama que acabas de dejar
comandos interesantes
git fetch VS git pull
- git pull = git fetch (+ git checkout) + git merge
- modo seguro:
git fetch origin git log --oneline main..origin/main git checkout main git log origin/main git merge origin/main
ramas
- renombrado rama en local y remoto
git checkout <old_name> && git branch -m <new_name> # o git branch -m <old_name> <new_name> git push -u origin <new_name> # y comprobar en remoto que todo ha ido bien git push origin :<old_name> # elimina la rama vieja del remoto!
- mover rama, trayendo solo los commits que se hayan realizado
git ck -b rama_destino git cherry-pick <commit1>..<commit2> # commit1^..commit2 para incluir commit1 en el movimiento git push origin rama_destino # envíamos los cambios git push origin :rama_origen # elimina la rama mal colocada
- traer los cambios de rama develop a la actual
git pull --rebase origin develop
- comandos con TAGs
git tag [-l] git show <tag> git tag -a <TAG> -m "<MENSAJE>" # tag local annotated git push origin <TAG> # subir tag a remoto git -d <tag> # borrar tag local git push --delete origin <TAG> # borrado tag en remoto
- actualizar listado ramas
git remote update origin --prune git branch -a
/via: https://stackoverflow.com/questions/36358265/when-does-git-refresh-the-list-of-remote-branches
- (ohshitgit) Sacar commit de una rama para llevarlo a una nueva
git branch nueva-rama git reset HEAD~ --hard git checkout nueva-rama
- (ohshitgit) Commit en rama equivocada
# deshaz el útlimo commit, pero deja los cambio disponibles git reset HEAD~ --soft git stash # muevete a la rama correcta git checkout nombre-de-la-rama-correcta git stash pop git add . # or add individual files git commit -m "your message here"; # ahora tus cambios estan en la rama correcta
- (ohshitgit) Commit en rama equivocada - cherry-pick
git checkout nombre-de-la-rama-correcta # coge el último commit de master git cherry-pick master # borralo de master git checkout master git reset HEAD~ --hard
pequeños cambios en commits (no push)
- (ohshitgit) agregar cambios al último commit
git add . git commit --amend --no-edit
- (ohshitgit) cambiar mensaje último commit
git commit --amend
retroceder o cambiar el pasado(rebase/reset)
- (ohsgitgit) todo lo hecho, en todas las ramas
git reflog # cada entrada tiene un HEAD@{index}
- (ohsgitgit) vuelta atrás
git reset HEAD@{index}
- cambiar el mensaje de un commit (el último -1)
git rebase -i HEAD^ # y marcar con reword
- fusionar varios commits
git rebase -i <commit>^ # con ^ se incluye el que indiquemos git rebase -i HEAD~n # los últimos n # marcar con SQUASH aquellos que queramos fusionar, dejando el mayor ancestro como destinatario de todos ellos # git push origin <rama> -f # fuerza la subida de los cambios
- anular último commit (se pierde)
git rebase -i HEAD^ # y marcar con drop
- anular último commit dejando en working area
git reset HEAD~1
ficheros
- recuperar un fichero
git checkout <COMMIT|HEAD|HEAD^> <path_file>
- ficheros modificados en commit concreto
git log --oneline --max-count=10 git diff-tree --no-commit-id --name-only -r <COMMIT_ID> git show --pretty="" --name-only <COMMIT_ID>
- seguir traza cambios a fichero
git log --follow -p -- <FILE> git log --stat <FILE>
git whatchanged [<FILE>]
- mantenido por razones históricas
diferencias entre commits
- diferencia de ficheros entre dos commits:
git diff --name-only SHA1 SHA2
- generar ZIP con ficheros cambiados entre 2 commits:
git archive --output=file.zip HEAD $(git diff --name-only SHA1 SHA2)
recuperar
- localizar fichero:
git log -- <fichero>
- recuperar fichero:
git checkout <COMMIT_ID> -- <fichero>
búsquedas
- localizar fichero
git log -- <fichero>
- seguir traza cambios a fichero
git log --follow -p -- <FILE>
- buscar ficheros y estatus
git log --name-status -- "*<FILE>*"
–
indica a git que lo que viene a continuación son rutas de ficheros y no ramas
- buscar líneas de código
git log -S"Hello, World!"