Last active
October 16, 2024 22:48
-
-
Save wojciech-kulik/17a2972deb8e0fef9bd7791b893f7db5 to your computer and use it in GitHub Desktop.
Git file history + diff (even if moved or renamed)
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
function file-history() { | |
if [ -z "$2" ]; then | |
file_pattern="$(basename "$1")" | |
else | |
file_pattern="$2" | |
fi | |
git log --oneline --abbrev-commit --follow "$1" | | |
fzf --ansi --preview "commit=\$(echo {1} | cut -d' ' -f1); \ | |
file=\$(git show --pretty='' --name-only \$commit | grep -i '$file_pattern'); \ | |
file=\$(echo \$file | sed 's/^$/./g'); \ | |
git show --color=always \$commit -- \"\$file\" | diff-so-fancy" | |
} | |
# Usage: | |
# file-history "relative/path/to/file.ext" | |
# file-history "relative/path/to/file.ext" "before_rename\|after_rename" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment