How can I know in git if a branch has been already rebased onto master?

This is very similar to How can I know in git if a branch has been already merged into master? but is about checking for rebased code. In the repository I am currently working on it seems that a few feature branches have been left hanging aground after their changes were rebased onto master. What is the best way for me to check that this has been done before I delete the branch?

Most of the suggestions on that branch suggest using the SHA id key of the last change on a branch to check for its presence in master. I can see that is the best way to be sure for merging but when you rebase this SHA is changed.

I have an answer that I will post too but I would like to know if people think there are better options.


Searching by the last commit message of the feature branch within the master branch's log works quite well.

On the master branch do:

 git log -i --grep="<summary>"

Where is a segment of the comment from the last commit in your feature branch. This presents you with the commit SHA for the master branch copy, the Author and Date of the commit; the last two of which are preserved by a rebase. If your Author, Date and Comments are similar then you can be confident that the change was rebased onto the branch who's log you are inspecting.

This will not work if the rebase was used to squash all the feature branch commits into a single commit on master.

There are possibly other issues with this method, please do post them in the comments or suggest better answers where you can.


In a case where the rebases are faithful to the original commit message @TafT's answer will work well. In addition, using

git log --oneline --cherry master...some-branch

will show = by every commit that has been copied exactly the same from some-branch to master.

If squashing and the like is taking place, commit messages are changed, or if your rebasing had conflicts neither solution will work. In this case I suggest the following (Checkout to detached HEAD so that we do not accidentally push this merge):

git checkout master~0
git merge some-branch

Unless your code has changed drastically, if the merge results in no change, then the branch has been rebased already. Otherwise, it obviously has not.

链接地址: http://www.djcxy.com/p/26060.html

上一篇: git列表远程分支,按提交数量排序

下一篇: 我怎么能在git中知道一个分支是否已经重新绑定到master?