Skip to content

Instantly share code, notes, and snippets.

@cristobal
Created April 11, 2022 12:09
Show Gist options
  • Save cristobal/2a78398ec4e291070e4c7c9699860a2f to your computer and use it in GitHub Desktop.
Save cristobal/2a78398ec4e291070e4c7c9699860a2f to your computer and use it in GitHub Desktop.
Find git commit when a package was introduced in the package.json file in a git repo.
prev_cmt=""
for cmt in $(git lg package.json | awk '{print $2}');
do
git co $cmt >/dev/null 2>&1
cat package.json | grep 'package-name' >/dev/null 2>&1
# will fail if does not find the package-name in the current commit
if [ $? -ne 0 ] ; then
echo "cmt: $cmt"
echo "prev_cmt: $prev_cmt"
git co main
break;
fi
# store the last seen commit
prev_cmt=$cmt
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment