Tips avanzados de Git

Tips avanzados de Git

Notas y scripts usados en mi charla sobre tips avanzados con Git.

Git trees y branches

Darle sentido a la historia

git log --pretty=oneline
git log --pretty='%h | %d %s (%cr) [%an]'
git log --pretty='%Cred%h%Creset |%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset %C(cyan)[%an]%Creset'
git log --pretty='%Cred%h%Creset |%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset %C(cyan)[%an]%Creset' --graph
git config --global alias.lg "git log --pretty='%Cred%h%Creset |%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset %C(cyan)[%an]%Creset' --graph"
git show HEAD --pretty='parent %Cred%p%Creset commit %Cred%h%Creset%C(yellow)%d%Creset%n%n%w(72,2,2)%s%n%n%w(72,0,0)%C(cyan)%an%Creset %Cgreen%ar%Creset'

git config --global alias.so "show --pretty='parent %Cred%p%Creset commit %Cred%h%Creset%C(yellow)%d%Creset%n%n%w(72,2,2)%s%n%n%w(72,0,0)%C(cyan)%an%Creset %Cgreen%ar%Creset'"

Seguimiento de cambios y depurar tu código

Commits que están en una rama pero no en la otra.

git log  A..B   # Show me commits only on B.
git log  A...B  # Show me commits only on A or only on B.
git diff A..B   # Show me changes only on A or only on B.
git diff A...B  # Show me changes only on B.
git log feature..main

git log main..feature

git log feature...main

git log --follow Molinos.Scato.Servicios/Impl/ServicioEstadoPuesto.cs

git log --follow --patch Molinos.Scato.Servicios/Impl/ServicioEstadoPuesto.cs

git log -Scalculator

git log -S".*is.*" --pickaxe-regex

git log -Gcalculator

git log -G".*is.*"

git log -L:subtract:calculator.c

git lg -L:ActualizarPuestos:Molinos.Scato.Servicios/Impl/ServicioEstadoPuesto.cs -s

.gitattributes

# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs     diff=csharp
*.sln    merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union

# Standard to msysgit
*.doc	 diff=astextplain
*.DOC	 diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot  diff=astextplain
*.DOT  diff=astextplain
*.pdf  diff=astextplain
*.PDF	 diff=astextplain
*.rtf	 diff=astextplain
*.RTF	 diff=astextplain

Se rompio el build pero donde?

git bisect start

git bisect bad <commit-ref>

git bisect good <commit-ref>

git bisect reset

git bisect start <bad-commit-ref> <good-commit-ref>

git bisect run <cmd>

git bisect reset

Conflictos: rerere

git config --global rerere.enabled true

Rescribir la historia

Editar

git commit --amend

git commit --amend -C <commit-ref>

Undo

git reflog master

git reflog

git show HEAD@{2}

git show master@{1}

git reset --hard master@{1}

git config --global alias.undo '!f() { git reset --hard $(git rev-parse --abbrev-ref HEAD)@{${1-1}}; }; f'

git undo 2

git undo

Cambiar la historia

git rebase -i HEAD~4

Un alias util para cambiar de rama y mezclar en una sola linea.

git config --global alias.qm "!git checkout $1; git merge @{-1}"