Last active
August 29, 2023 07:35
-
-
Save damianwajer/3ff13b13a8e67b29b00c903405545c48 to your computer and use it in GitHub Desktop.
[Git] Snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Git apply diff | |
pbpaste | git apply | |
# Nice Git log with tags | |
git log --oneline --decorate | |
# Show commit difference between two branches | |
git log --oneline --decorate master..HEAD | |
# Log after specific date | |
git log --after="2018-09-27 10:00" | |
# View file history (even if deleted) | |
git log --all --full-history -- path/to/file | |
# Search files with grep | |
git ls-files | grep png | |
# Clean untracked files and directories | |
git clean -dfx output | |
# Safer `git push --force` | |
git push --force-with-lease | |
# Ignore local changes of tracked file | |
git update-index --assume-unchanged my_file | |
# Track changes again | |
git update-index --no-assume-unchanged my_file | |
# List all "assume-unchanged" files from current directory | |
git ls-files -v | grep -E "^[a-z]" | |
git ls-files -v | grep '^h' | |
# Empty commit | |
git commit --allow-empty -m "Trigger build" | |
# Debug .gitignore | |
git check-ignore -v my_file | |
# Create a new branch and switch to it | |
git checkout -b my_new_branch | |
# Switch to the previous branch | |
git checkout @{-1} | |
# Switch to the previous branch (shorthand) | |
git checkout - | |
# Restore the file from other branch | |
git checkout master -- path/to/file | |
# VSC as global git editor | |
git config --global core.editor "code --wait" | |
# Undo the X number of commits (HEAD~X) | |
git reset --soft HEAD~1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment