# 2010-08-18  Git中判断一个commit是否在某个branch中

方法1：`git branch --contains commit`

方法2：查找reflog `git reflog show --all | grep a871742`

会有类似如下的结果：`a871742 refs/heads/completion@{0}: commit (amend): mpc-completion: total rewrite`，其中 completion 就是所在的 branch

注：`git reflog show`等价于`git log -g --abbrev-commit --pretty=oneline`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://blog.log4think.com/find-commit-in-branch.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
