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 [25/04/2022 02:33] – [comandos interesantes] matetech:git:start [09/05/2025 04:09] (actual) – [related] mate
Línia 5: Línia 5:
 {{topic>git}} {{topic>git}}
   * [[tech:git:server]]   * [[tech:git:server]]
 +  * [[tech:git:curs]]
 +  * [[tech:git:repo-lectura]]
  
 == cheatsheet == cheatsheet
Línia 17: Línia 19:
   * [[https://nvie.com/posts/a-successful-git-branching-model/]]   * [[https://nvie.com/posts/a-successful-git-branching-model/]]
  
 +== doc
 +  * [[https://git-scm.com/book/es/v2]]
 +  * [[https://esparta.github.io/gitimmersion-spanish/index.html]]
 == todo == todo
 <callout type="warning" title="git extras" icon="true">https://github.com/tj/git-extras/</callout> <callout type="warning" title="git extras" icon="true">https://github.com/tj/git-extras/</callout>
Línia 43: 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 55: 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]]
  
-<code bashrenombrado rama en local y remoto>+=== 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 
 +<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 62: 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 69: Línia 91:
 </code> </code>
  
-<code bash; cambiar el mensaje de un commit (el último -1) >+<code bash traer los cambios de rama develop a la actual> 
 +git pull --rebase origin develop 
 +</code> 
 + 
 +<code bash 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 
 +</code> 
 + 
 +<code bash actualizar listado ramas> 
 +git remote update origin --prune 
 +git branch -a 
 +</code> 
 +/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) 
 +<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 80: Línia 155:
 </code> </code>
  
-<code bashanular último commit > +<code bash anular último commit (se pierde)
-git rebase -i HEAD^ # y marcar con reword+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>
  
 +=== ficheros
 <code bash; recuperar un fichero > <code bash; recuperar un fichero >
 git checkout <COMMIT|HEAD|HEAD^> <path_file> git checkout <COMMIT|HEAD|HEAD^> <path_file>
 </code> </code>
  
-<code bash; traer los cambios de rama develop a la actual> +<code bash (ohshitgit) recuperar un fichero > 
-git pull --rebase origin develop+# 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>
  
-<code bash; comandos con TAGs> +<code bash ficheros modificados en commit concreto>
-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 +
-</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 110: 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; actualizar listado ramas+<code bash>git whatchanged [<FILE>]</code
-git remote update origin --prune +  * [[https://git-scm.com/docs/git-whatchanged]] 
-git branch -a +  * mantenido por razones históricas 
-</code> + 
-/via: [[https://stackoverflow.com/questions/36358265/when-does-git-refresh-the-list-of-remote-branches]]+==== 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> 
 +  * generar ZIP con ficheros cambiados entre 2 commits:<code bash>git archive --output=file.zip HEAD $(git diff --name-only SHA1 SHA2)</code> 
 +  * /via:[[https://www.solucionex.com/blog/ficheros-modificados-entre-dos-commits-con-git]] 
 +==== recuperar 
 +  * localizar fichero: <code bash>git log -- <fichero></code> 
 +  * recuperar fichero: <code bash>git checkout <COMMIT_ID> -- <fichero></code> 
 +  * [[https://recoverit.wondershare.es/file-recovery/recover-files-from-local-repository-git.html]] 
 + 
 +=== búsquedas 
 +<code bash localizar fichero>git log -- <fichero></code> 
 +<code bash seguir traza cambios a fichero>git log --follow -p -- <FILE></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.1650879196.txt.gz
  • Darrera modificació: 25/04/2022 02:33
  • per mate