Check if a branch has been merged to master and hasn't been reverted out

I would like to create a tool that will list out the names of feature branches that have been merged into a branch (e.g. master), but excluding branches whose merges have since been reverted.

For example:

  • How to listen to submodule changes without cloning in Jenkinso
  • What different Git repositories do I need?
  • Git: configure patterns for difftool and mergetool
  • There is nothing changed, but eclipse egit marks the file as changed
  • Git post-receive hook doesn't remove deleted files from master
  • Is there a good way to rebase and merge the project.pbxproj file using git?
  •    /--*--*--*--\                           feature
      /             \
    ------*--*-------*--*--*--*-------------*  master
                     ^     ^
                     |     | git revert -m1 abc1 (#abc2)
                     | git merge --no-ff feature (#abc1)

    I understand that git branch --contains feature will return master, and I understand why, but I would like to know if there is a simple-enough way to exclude branches that have since been reverted out.

    If not, what would be optimal solution? Comparing diffs?

  • Github commits using SSH key
  • How to develop multiple pip packages in a git project?
  • Bitbucket is alarming that my git repo is too large but I cannot confirm large files
  • Git sees non-existent local changes and prevents pull
  • Finding the size of a push
  • Managing Git Users and Passwords
  • 3 Solutions collect form web for “Check if a branch has been merged to master and hasn't been reverted out”

    First, from “How can I know in git if a branch has been already merged into master?”, you can check if your feature branch is part of git branch --merged or check git merge-base to find the merged commit.

    Second, the question “Telling if a Git commit is a Merge/Revert commit” does warn us that a revert commit can be hard to find, and only advocate for the revert message boilerplate in the commit message.

    Do the simple search which is

    git log --grep="This reverts commit ${merge_sha}"

    If they hand edited the commit message then you are stuck with something awful like

    matchId=$(git diff  ${merge_sha}^! | grep -v -e "^diff --git" -e "^--- " -e "^+++ " -e "^index " | sha1sum
    for sha in $(git revlist ${merge_sha}..HEAD)
      shaId=$(git diff  -R ${sha}^! | grep -v -e "^diff --git" -e "^--- " -e "^+++ " -e "^index " | sha1sum)
      if [ ${matchId} == ${shaId} ]
          echo "${sha} might be a ninja revert of ${merge_sha}"

    This could obviously be improved a lot to reverse the fields of some of the lines that I am excluding with grep currently. You’d basically be re-implementing git patch-id but allowing it to have the a/b files all reversed (maybe there is an option to allow that already, but I don’t know what it is)

    An easy way to do this would be to simply grep through the log:

    git log | grep "^commit " | grep <commit-id>
    • git log — shows the log of all the commits
    • grep "^commit " — filters by commit ID (since they all start with “commit”)
    • grep <commit-id>— filter by just the commit you care about

    NOTE—This may not work if git changes the commit ID.

    Git Baby is a git and github fan, let's start git clone.