Imagine you got a Git repository with a long history - equivalent to log - and you want find a changeset with a comment containing a word or some words and you want to get the commit SHA
to quickly cherry pick that commit to your target branch. This is easier using Azure Devops or some tool, but how to quickly search the log.
First we define a search log shell function inside our git config file .gitconfig :
searchlog = "!f() { git --no-pager log --color-words --all --decorate --graph -i --grep \"$1\"; }; f"
Now we can search the log quickly using a wildcard:
git searchlog "visning.*av.*nåtidslinje.*"
We separate our search words with the .* regex syntax and we can search our git log for multiple keywords quickly and get a nice presentation of commits with commit messages matching our log.
And now we have a quick way to find our Git commits through the log and the command line to overcome our needly in the haystack scenario.
Share this article on LinkedIn.
No comments:
Post a Comment