Skip to content

Instantly share code, notes, and snippets.

@hminnovation
Last active November 2, 2020 12:03
Show Gist options
  • Save hminnovation/b54c14a48f14be7da89bdfab97f7e1fb to your computer and use it in GitHub Desktop.
Save hminnovation/b54c14a48f14be7da89bdfab97f7e1fb to your computer and use it in GitHub Desktop.
Find text in git repo on any branch

Find a file that's stuck on a branch and not been merged (and / or has been deleted)

This is a pain and something that can easily happen. Specifically had it with a readme file with some important documentation that we didn't want to, as a team, try and re-document.

This was the most "pragmatic" (ergo fastest to find what we were looking for)

From https://stackoverflow.com/questions/15292391/is-it-possible-to-perform-a-grep-search-in-all-the-branches-of-a-git-project

git log -p --all -S 'search string'

git log -p --all -G 'match regular expression'

These log commands list commits that add or remove the given search string/regex, (generally) more recent first. The -p option causes the relevant diff to be shown where the pattern was added or removed, so you can see it in context.

Having found a relevant commit that adds the text you were looking for (eg. 8beeff00d), find the branches that contain the commit:

git branch -a --contains 8beeff00d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment