A Bash script that helps you find branches containing a specific commit in a Git repository. The script filters branches based on the GitFlow naming conventions. The output lists the versions in which the commit exists, sorted according to SemVer.
./find_commit_versions.sh -c <commit-hash> [-r <repository-path>]
- -c (required): The commit hash to search for in the branches.
- -r (optional): The path to the Git repository. Defaults to the current directory if not provided.
./find_commit_versions.sh -c cc7486d -r /path/to/git/repository
- Checks if the required commit hash argument is provided.
- Validates the provided repository path, or uses the current directory as the default path.
- Fetches the latest commits from the remote silently.
- Finds all remote branches containing the specified commit.
- Filters the branches based on the following conditions:
- The branch name is exactly "master".
- The branch name matches the pattern "release/v{major}.{minor}.{patch}", where major, minor, and patch are numbers separated by periods.
- Replaces the "master" or "main" branch name with "production", replaces "develop" with "development" and extracts versions from release branches.
- Sorts the output list according to SemVer (major, minor, and patch).
The commit cc7486d exists in the following versions:
development
production
v1.2.1
v1.2.2
v1.3.0