# Comparing Commits or Branches

If the commits (or head commits of two branches) are close in the graph, we can select one and select another with CTRL key press. Then we can see the diff in the diff view.

If they are far away, we can right click one commit/branch and select the `Compare` menu

![](/files/-LS9iUUxlxPbhxBttxva)

\
In the branch/commit compare form you can swap the BASE and the HEAD, or compare to merge base, or even select another commit to compare. Unfortunately it doesn't have a files filter right now.

Command line:

```
git diff <branchA>..<branchb>  # also works for commits
git diff <branchA>...<branchb> # compare to merge base.
# for example
git diff main..origin/main
```

#### Merge Base <a href="#merge-base" id="merge-base"></a>

```
         o---o---o---o---o---o---o---B
        /
---o---merge base is here---o---o---o---A
```


---

# 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://gittutorial.gitbook.io/practical-git-via-gitextensions/how-to-compare-commits-or-branches.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.
