# 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

![](https://1560106033-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LS9bmsupx6ftQfO0PH7%2F-LS9iAHRkm91m8RIpy7K%2F-LS9iUUxlxPbhxBttxva%2Fimage.png?alt=media\&token=06befbe7-0775-441c-ba75-2405d232a8ea)

\
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
```
