↑ ↓ select, Enter open, Esc close

#git

16 one-liners with this tag.

All one-liners tagged git

Change the message of the last commit

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

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
cautionGit

Delete local branches that are already merged

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

Discard local changes to a file

$git restore wp-config.php
destructiveGit

Find commits that added or removed specific text

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

Find out who changed specific lines of a file

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

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
harmlessGit

Fix the Git error dubious ownership on servers

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

Hard reset a working copy to the remote branch

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

Recover lost commits using the reflog

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

Restore an accidentally deleted branch

$git branch feature/contact-form a1b2c3d
cautionGit

Search for text in all versions of a repository

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

Show differences between two branches

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

Show the Git history compactly as a graph

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

Stop tracking a file but keep it locally

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

Temporarily save local changes with git stash

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

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.