#!/bin/bash # Define the filename and search keyword filename="path/to/file.R" search_term="deleted_string" # Retrieve the commit hashes that modified the file commit_hashes=$(git log --oneline --follow -- "$filename" | cut -d " " -f 1) # Loop through the commit hashes for commit_hash in $commit_hashes; do # Search for the keyword in the file for each commit grep_result=$(git grep -c "$search_term" "$commit_hash" -- "$filename") if [ "$grep_result" != "" ]; then echo "############################################" echo "Found '$search_term' in commit: $commit_hash" echo "############################################" file_content=$(git show "$commit_hash":"$filename") printf "%s\n" "$file_content" fi done
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter