#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'
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
Delete local branches that are already merged
$git branch --merged main | grep -vE '^[*+]|^\s*(main|main|master|develop)$' | xargs -r git branch -d
Discard local changes to a file
$git restore wp-config.php
Find commits that added or removed specific text
$git log -S 'define('WP_DEBUG'' --oneline --all
Find out who changed specific lines of a file
$git blame -L 10,40 wp-config.php
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
Fix the Git error dubious ownership on servers
$git config --global --add safe.directory /var/www/vhosts/example.com/httpdocs
Hard reset a working copy to the remote branch
$git fetch origin && git reset --hard origin/main
Recover lost commits using the reflog
$git reflog --date=iso -n 30
Restore an accidentally deleted branch
$git branch feature/contact-form a1b2c3d
Search for text in all versions of a repository
$git rev-list --all | xargs git grep -F 'DB_PASSWORD'
Show differences between two branches
$git diff --stat main...feature/contact-form
Show the Git history compactly as a graph
$git log --oneline --graph --decorate --all -n 30
Stop tracking a file but keep it locally
$git rm --cached wp-config.php
Temporarily save local changes with git stash
$git stash push -u -m 'Hotfix test on the server'