Skip to content

Instantly share code, notes, and snippets.

@gmoura
Last active February 23, 2022 21:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmoura/a15794d749efea2b9dd6d66dc71d51c4 to your computer and use it in GitHub Desktop.
Save gmoura/a15794d749efea2b9dd6d66dc71d51c4 to your computer and use it in GitHub Desktop.
Git Cookbook #1

Git Cookbook #1

Rebase x Merge

Merge

$ git checkout feature

$ git merge master

Rebase

Simple way

$ git checkout feature

$ git rebase master

Interative

$ git rebase -i

Safe commands

Safe merge

$ git merge --no-ff

Add changes

Adding parcialment

$ git add -p <file>

Undo things

Reset to Head

$ git reset --hard HEAD

Reset to remote Head

$ git reset --hard origin/master

Checkout from remote file

$ git checkout origin/branch_name -- <path or file>

Fix commit

$ git commit --amend

Revert to some commit

$ git revert <commit_id>

Diff

Compare a unique file between two commits

git diff <commit_id> <commit_id> <file>

Stash things

$ git stash save "Xablau"

Recover and delete stash

$ git stash pop

Log

Log with files

git log --stat

Log with file and filter by file type

git log --stat -- "*.js"

git lg

~/.gitconfig

[alias]
lg1 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n''          %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
lg = !"git lg1"

Cools links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment