# git-when-merged **Repository Path**: mirrors_devzero2000/git-when-merged ## Basic Information - **Project Name**: git-when-merged - **Description**: Determine when a particular commit was merged into a git branch - **Primary Language**: Unknown - **License**: GPL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-03-03 - **Last Updated**: 2026-05-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # `git when-merged` `git when-merged` helps you figure out when and why a commit was merged into a branch. If you use standard Git workflows, then you create a feature branch for each feature that you are working on. When the feature is complete, you merge it into your `master` branch. You might even have sub-feature branches that are merged into a feature branch before the latter is merged. In such a workflow, the first-parent history of `master` consists mainly of merges of feature branches into the mainline. `git when-merged` can be used to ask, "When (and why) was commit C merged into the current branch?" The simplest way to use it is ```ShellSession $ git when-merged 87c248f refs/heads/master 50f577451448a407ee8e78ed62aa09d209c91652 ``` This command looks along the first-parent history of the current branch to find the merge commit that first brought commit `87c248f` into the branch's history. The guilty merge commit in this case is `50f5774`. Add the `-l` option to see the log for that merge, which will hopefully explain what feature was being merged and by whom: ```ShellSession $ git when-merged -l 87c248f refs/heads/master 50f577451448a407ee8e78ed62aa09d209c91652 commit 50f577451448a407ee8e78ed62aa09d209c91652 (github/master, master) Merge: f79a45d 87c248f Author: Michael Haggerty Date: Mon Jul 11 07:55:19 2016 +0200 Merge pull request #9 from mhagger/recursive-option Add a `--recursive`/`-r` option ``` There are many more options; see below. ## Installation * Clone the repo somewhere on your system. * Ensure that `/bin/git-when-merged` is executable. * Put the contents of `/bin` on your `$PATH`. That's it! Or, using Homebrew: ```ShellSession $ brew update $ brew install git-when-merged ``` ## Usage git when-merged [OPTIONS] COMMIT [BRANCH...] Find the merge commit that brought `COMMIT` into the specified `BRANCH`(es). Specifically, look for the oldest commit on the first-parent history of each `BRANCH` that contains the `COMMIT` as an ancestor. ``` positional arguments: commit The commit whose destiny you would like to determine. branch The destination branch(es) into which might have been merged. (Actually, BRANCH can be an arbitrary commit, specified in any way that is understood by git-rev-parse(1).) If neither nor --pattern/-p nor --default/-s is specified, then HEAD is used. optional arguments: -h, --help show this help message and exit --pattern PATTERN, -p PATTERN Show when COMMIT was merged to the references matching the specified regexp. If the regexp has parentheses for grouping, then display in the output the part of the reference name matching the first group. --name NAME, -n NAME Show when COMMIT was merged to the references matching the configured pattern(s) with the given name (see whenmerged..pattern below under CONFIGURATION). --default, -s Shorthand for "--name=default". --recursive, -r Follow merges back recursively. --show-commit, -c Display only the SHA-1 of the merge commit. Exit with a nonzero exit code if the commit was not merged via a merge commit. --show-branch, -b Display the range of commits that were merged at the same time as the specified commit. Exit with a nonzero exit code if the commit was not merged via a merge commit. This option also affects the behavior of --log and --visualize. --abbrev N Abbreviate commit SHA-1s to the specified number of characters (or more if needed to avoid ambiguity). See also whenmerged.abbrev below under CONFIGURATION. --no-abbrev Do not abbreviate commit SHA-1s. --describe Describe the merge commit in terms of the most recent tag reachable from the commit (see git-describe(1)) --describe-contains Describe the merge commit in terms of a nearby tag that contains it (see git-describe(1)) --log, -l Show the log for the merge commit. When used with "--show-branch/-b", show the log for all of the commits that were merged at the same time as the specified commit. --diff, -d Show the diff for the merge commit. --visualize, -v Visualize the merge commit using gitk. When used with "--show-branch/-b", only show the branch(es) that were merged at the same time as the specified commit. Examples: git when-merged 0a1b # Find the merge commit that brought # commit 0a1b into the current branch git when-merged 0a1b v1.10 v1.11 # Find merge into given tags/branches git when-merged 0a1b -p feature-[0-9]+ # Specify tags/branches by regex git when-merged 0a1b -n releases # Use whenmerged.releases.pattern git when-merged 0a1b -s # Use whenmerged.default.pattern git when-merged -r 0a1b # If the commit was merged indirectly, # show each intermediate merge. git when-merged -l 0a1b # Show the log for the merge commit git when-merged -lb 0a1b # Show log for the whole merged branch git when-merged -v 0a1b # Visualize the merge commit in gitk git when-merged -vb 0a1b # Visualize the whole merged branch git when-merged -d 0a1b # Show the diff for the merge commit git when-merged -c 0a1b # Print only the merge's SHA-1 Configuration: whenmerged..pattern Regular expressions that match reference names for the pattern called . A regexp is sought in the full reference name, in the form "refs/heads/master". This option can be multivalued, in which case references matching any of the patterns are considered. Typically the pattern will be chosen to match master and/or significant release branches or tags, or perhaps their remote-tracking equivalents. For example, git config whenmerged.default.pattern '^refs/heads/master$' git config --add whenmerged.default.pattern '^refs/heads/maint$' or git config whenmerged.releases.pattern '^refs/tags/release-' whenmerged.abbrev If this value is set to a positive integer, then Git SHA-1s are abbreviated to this number of characters (or longer if needed to avoid ambiguity). This value can be overridden using --abbrev=N or --no-abbrev. ``` `git when-merged` is originally based on [the suggestion here](http://stackoverflow.com/questions/8475448/find-merge-commit-which-include-a-specific-commit).