Search entire repository commit history for a string
Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.
Summary
The purpose of this knowledge article is to detail a method for searching through an individual repositories entire commit history for a particular string of text
At present, our existing code search functionality within the UI is limited to the main branch, and does not search through files that are larger than 320kb in size
The method highlighted in the steps below will search all branches in the repository and does not have this file size restriction
Solution
Procedure
Searching through a repository commit history can be achieved using a combination of the git grep/git rev-list commands, these commands can then be fine-tuned to display the output in a human-readable format:
You can execute the most basic of search commands by simply using the traditional git grep command, the command will print a list of binary filenames that match the string "test" in the example below but these do not include detailed information concerning the commit history:
EXAMPLE
1 2 3 4 5
> git grep "test" bitbucket-pipelines.yml:# Use a skeleton to build, test and deploy using manual and parallel steps bitbucket-pipelines.yml: mytestcache: bitbucket-pipelines.yml: - testcache.zip bitbucket-pipelines.yml: - test.sh
When you combine the git grep command with the git rev-list command - this will show you more detailed information (eg commit hash, line number) for each and every commit across all branches where the "test" string appears.
EXAMPLE
1 2 3 4 5 6 7
> git grep --break --heading --line-number "test" $(git rev-list --abbrev-commit --all) 9f1a0cd:bitbucket-pipelines.yml 2:# Use a skeleton to build, test and deploy using manual and parallel steps 10: name: Deploy to test 13: - echo $test 14: - echo "TESTING $test"
(Optional): The above commands are listed as a guide only, if you wished to customise these so that they produce a different output you can feel free to do so by exploring the extra flags/functions of the git grep/git rev-list commands
If you are unable to successfully gather the information that you require after following this article - please feel free to raise a support ticket or raise a community support ticket for further assistance.
Was this helpful?