↑ ↓ select, Enter open, Esc close

Git

Git commands for everyday work and emergencies: search the history, undo changes, clean up branches and recover things you deleted by accident.

16 one-liners: 7 harmless, 7 caution, 2 destructive

All Git one-liners

Change the message of the last commit

$git commit --amend -m 'Fix: correct cache path in configuration'
caution

Create an annotated tag and push it to the remote

$git tag -a v1.4.0 -m 'Release 1.4.0' && git push origin v1.4.0
caution

Delete local branches that are already merged

$git branch --merged main | grep -vE '^[*+]|^\s*(main|main|master|develop)$' | xargs -r git branch -d
caution

Discard local changes to a file

$git restore wp-config.php
destructive

Find commits that added or removed specific text

$git log -S 'define('WP_DEBUG'' --oneline --all
harmless

Find out who changed specific lines of a file

$git blame -L 10,40 wp-config.php
harmless

For the websites on your server

Free SEO and PageSpeed check

GENLOC.SEO analyzes any domain for load time, Core Web Vitals and on-page issues and tells you in plain words what is going on. Available in 11 languages.

by GENLOC.NETWORK, the team behind myline.de

Find the largest files in the entire Git history

$git rev-list --objects --all | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' | awk '$1=="blob"' | sort -k3 -rn | head -n 20
harmless

Fix the Git error dubious ownership on servers

$git config --global --add safe.directory /var/www/vhosts/example.com/httpdocs
caution

Hard reset a working copy to the remote branch

$git fetch origin && git reset --hard origin/main
destructive

Recover lost commits using the reflog

$git reflog --date=iso -n 30
harmless

Restore an accidentally deleted branch

$git branch feature/contact-form a1b2c3d
caution

Search for text in all versions of a repository

$git rev-list --all | xargs git grep -F 'DB_PASSWORD'
harmless

Show differences between two branches

$git diff --stat main...feature/contact-form
harmless

Show the Git history compactly as a graph

$git log --oneline --graph --decorate --all -n 30
harmless

Stop tracking a file but keep it locally

$git rm --cached wp-config.php
caution

Temporarily save local changes with git stash

$git stash push -u -m 'Hotfix test on the server'
caution

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.