From: Bryan Turner Date: Thu, 19 Dec 2019 03:09:36 GMT Subject: Re: How to determine a branch whether has a specified commit Message-ID: In-Reply-To: <62a8f522.6873.16f1c0243f6.Coremail.wuzhouhui14@mails.ucas.ac.cn> On Wed, Dec 18, 2019 at 6:42 PM wuzhouhui wrote: > > Hi, > > I know > git branch --contains > can display all local branches that has specified commit. However, specify a > branch and commit, I don't know how to determine whether this branch contains > this commit. > > I think > git branch --contains | grep "Combine" the two commands: git branch --contains . That will either output the branch's name, if it contains the commit, or nothing if it doesn't. A different approach would be something like: git rev-list --count ^. If that returns a count of 0, it means the commit is reachable from the branch. Otherwise, it'll output some positive count indicating how many commits (including the specific commit you asked about) are not reachable from the branch. (I suspect you don't really need the count, so you could also use "-1" instead of "--count".) Hope this helps, Bryan