Last active
August 30, 2016 07:47
-
-
Save hamsterbacke23/410f31cf4ebe8e9cd364 to your computer and use it in GitHub Desktop.
git-tricks.sh
This file contains 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
# Show commit diff | |
git diff COMMIT^ COMMIT | |
# Search for commit with message | |
git log --all --grep='Build 0051' | |
# Search for file with globbing | |
git log --all -- '**/my_file.png' | |
# Last commit affecting a file | |
git rev-list -n 1 HEAD -- <file_path> | |
# Restore file | |
git checkout <deleting_commit>^ -- <file_path> | |
# Show my commits for today | |
git log --since="6am" --author="Tobias" | |
# Remove file from git, not the file itself | |
git rm --cached file.txt | |
# Undo Commit | |
# http://stackoverflow.com/questions/927358/how-to-undo-the-last-commit | |
# git commit ... << undo this | |
git reset --soft HEAD~1 | |
# Restore destroyed commit | |
git reflog | |
git checkout -b someNewBranchName shaYouDestroyed | |
# Remove from git without deleting file | |
git rm --cached -r somedir | |
# Get all files affected by commits between start and end | |
git diff -w --name-only --diff-filter=ACMRTUXB <STARTSHA>..<ENDSHA> | |
# Get all deleted files affected by commits between start and end | |
git log <STARTSHA>..<ENDSHA> --all --pretty=format: --name-only --diff-filter=D | sort -u | |
# Delete remote tag | |
git tag -d <TAG> | |
git push origin :refs/tags/<TAG> | |
# Add only changes without whitespace | |
# http://stackoverflow.com/questions/3515597/add-only-non-whitespace-changes | |
git diff -w --no-color | git apply --cached --ignore-whitespace | |
# Git merge chunks | |
git cherry-pick -n <commit> | |
git checkout -p | |
## Git diff spaces: http://stackoverflow.com/questions/3231759/how-can-i-visualize-per-character-differences-in-a-unified-diff-file | |
#Versions with less noisy output than git diff --word-diff-regex=<re> and that require less typing than, but are equivalent to, git git diff --color-words --word-diff-regex=<re>. | |
#Simple (does highlight space changes): | |
git diff --color-words | |
#Simple (highlights individual character changes; does not highlight space changes): | |
git diff --color-words=. | |
# More complex (does highlight space changes): | |
git diff --color-words='[^[:space:]]|([[:alnum:]]|UTF_8_GUARD)+' | |
# Look for string in git log | |
git log -G 'my string' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment