Diferències

Ací es mostren les diferències entre la revisió seleccionada i la versió actual de la pàgina.

Enllaç a la visualització de la comparació

Ambdós costats versió prèvia Revisió prèvia
Següent revisió
Revisió prèvia
tech:git:start [10/11/2023 00:02] matetech:git:start [09/05/2025 04:09] (actual) – [related] mate
Línia 6: Línia 6:
   * [[tech:git:server]]   * [[tech:git:server]]
   * [[tech:git:curs]]   * [[tech:git:curs]]
 +  * [[tech:git:repo-lectura]]
  
 == cheatsheet == cheatsheet
Línia 47: Línia 48:
   * [[tech:git:autopush]]   * [[tech:git:autopush]]
   * [[tech:git:diff]]   * [[tech:git:diff]]
 +
 +== errores
 +  * [[tech:git:error:thread]]
 == tips == tips
   * HEAD == @   * HEAD == @
Línia 59: Línia 63:
   * [[tech:git:difftool]]   * [[tech:git:difftool]]
   * [[https://www.atlassian.com/git/tutorials/learn-git-with-bitbucket-cloud|git bitbucket tutorial]]   * [[https://www.atlassian.com/git/tutorials/learn-git-with-bitbucket-cloud|git bitbucket tutorial]]
 +  * [[https://ohshitgit.com/es]]
  
 +=== git fetch VS git pull
 +  * git pull = git fetch (+ git checkout) + git merge
 +  * modo seguro:<code bash>git fetch origin
 +git log --oneline main..origin/main
 +git checkout main
 +git log origin/main
 +git merge origin/main</code>
 +
 +  * [[https://www.atlassian.com/es/git/tutorials/syncing/git-fetch]]
 +  * [[https://www.atlassian.com/es/git/tutorials/using-branches/git-checkout]]
 +  * [[https://www.atlassian.com/es/git/tutorials/using-branches/git-merge]]
 +  * [[https://www.atlassian.com/es/git/tutorials/syncing/git-pull]]
 === ramas === ramas
-<code bashrenombrado rama en local y remoto>+<code bash renombrado rama en local y remoto>
 git checkout <old_name> && git branch -m <new_name> # o git branch -m <old_name> <new_name> 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 -u origin <new_name> # y comprobar en remoto que todo ha ido bien
Línia 67: Línia 84:
 </code> </code>
  
-<code bashmover rama, trayendo solo los commits que se hayan realizado >+<code bash mover rama, trayendo solo los commits que se hayan realizado >
 git ck -b rama_destino git ck -b rama_destino
 git cherry-pick <commit1>..<commit2> # commit1^..commit2 para incluir commit1 en el movimiento git cherry-pick <commit1>..<commit2> # commit1^..commit2 para incluir commit1 en el movimiento
Línia 74: Línia 91:
 </code> </code>
  
-<code bashtraer los cambios de rama develop a la actual>+<code bash traer los cambios de rama develop a la actual>
 git pull --rebase origin develop git pull --rebase origin develop
 </code> </code>
  
-<code bashcomandos con TAGs>+<code bash comandos con TAGs>
 git tag [-l] git tag [-l]
 git show <tag> git show <tag>
Línia 87: Línia 104:
 </code> </code>
  
-<code bashactualizar listado ramas>+<code bash actualizar listado ramas>
 git remote update origin --prune git remote update origin --prune
 git branch -a git branch -a
Línia 93: Línia 110:
 /via: [[https://stackoverflow.com/questions/36358265/when-does-git-refresh-the-list-of-remote-branches]] /via: [[https://stackoverflow.com/questions/36358265/when-does-git-refresh-the-list-of-remote-branches]]
  
 +<code bash (ohshitgit) Sacar commit de una rama para llevarlo a una nueva>
 +git branch nueva-rama
 +git reset HEAD~ --hard
 +git checkout nueva-rama
 +</code>
 +
 +<code bash (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
 +</code>
 +<code bash (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
 +</code>
 +
 +=== pequeños cambios en commits (no push)
 +<code bash (ohshitgit) agregar cambios al último commit>git add .
 +git commit --amend --no-edit</code>
 +
 +<code bash (ohshitgit) cambiar mensaje último commit>git commit --amend</code>
 === retroceder o cambiar el pasado(rebase/reset) === retroceder o cambiar el pasado(rebase/reset)
-<code bashcambiar el mensaje de un commit (el último -1) >+<code bash (ohsgitgit) todo lo hecho, en todas las ramas>git reflog # cada entrada tiene un HEAD@{index}</code> 
 +<code bash (ohsgitgit) vuelta atrás>git reset HEAD@{index}</code> 
 +<code bash cambiar el mensaje de un commit (el último -1) >
 git rebase -i HEAD^ # y marcar con reword git rebase -i HEAD^ # y marcar con reword
 </code> </code>
Línia 105: Línia 155:
 </code> </code>
  
-<code bashanular último commit (se pierde)>+<code bash anular último commit (se pierde)>
 git rebase -i HEAD^ # y marcar con drop git rebase -i HEAD^ # y marcar con drop
 </code> </code>
  
-<code bashanular último commit dejando en working area>+<code bash anular último commit dejando en working area>
 git reset HEAD~1 git reset HEAD~1
 </code> </code>
Línia 118: Línia 168:
 </code> </code>
  
-<code bashficheros modificados en commit concreto>+<code bash (ohshitgit) recuperar un fichero > 
 +# busca el hash del commit anterior de cuando se cambio el archivo 
 +git log 
 +# usa las flechas para moverte para arriba y abajo en la historia 
 +# una vez que encontraste el commit, guarda su hash 
 +git checkout [hash guardado] -- path/to/file 
 +# la version anterior del archivo estará en tu index 
 +git commit -m "Waw, no tienes que hacer copiar-pegar para deshacer" 
 +</code> 
 + 
 +<code bash ficheros modificados en commit concreto>
 git log --oneline --max-count=10 git log --oneline --max-count=10
 git diff-tree --no-commit-id --name-only -r <COMMIT_ID> git diff-tree --no-commit-id --name-only -r <COMMIT_ID>
Línia 124: Línia 184:
 </code> </code>
  
-<code bashseguir traza cambios a fichero>+<code bash seguir traza cambios a fichero>
 git log --follow -p -- <FILE> git log --follow -p -- <FILE>
 +git log --stat <FILE>
 </code> </code>
 +  * https://git-scm.com/docs/git-log
 +
 +<code bash>git whatchanged [<FILE>]</code>
 +  * [[https://git-scm.com/docs/git-whatchanged]]
 +  * mantenido por razones históricas
  
 ==== diferencias entre commits ==== diferencias entre commits
 +  * (ohshitgit) diferencias de ficheros en **staged**:<code bash>git diff --staged</code>
   * diferencia de ficheros entre dos commits:<code bash>git diff --name-only SHA1 SHA2</code>   * diferencia de ficheros entre dos commits:<code bash>git diff --name-only SHA1 SHA2</code>
   * generar ZIP con ficheros cambiados entre 2 commits:<code bash>git archive --output=file.zip HEAD $(git diff --name-only SHA1 SHA2)</code>   * generar ZIP con ficheros cambiados entre 2 commits:<code bash>git archive --output=file.zip HEAD $(git diff --name-only SHA1 SHA2)</code>
Línia 138: Línia 205:
  
 === búsquedas === búsquedas
-<code bashseguir traza cambios a fichero> +<code bash localizar fichero>git log -- <fichero></code> 
-git log --follow -p -- <FILE> +<code bash seguir traza cambios a fichero>git log --follow -p -- <FILE></code
-</code>+<code bash buscar ficheros y estatus>git log --name-status -- "*<FILE>*"</code> 
 +  * ''--'' indica a git que lo que viene a continuación son rutas de ficheros y no ramas 
 +<code bash buscar líneas de código>git log -S"Hello, World!"</code> 
 +/via: [[https://www.atlassian.com/git/tutorials/git-log]]
  • tech/git/start.1699603326.txt.gz
  • Darrera modificació: 10/11/2023 00:02
  • per mate