154

I'm trying to view commits made by a specific user, and want to remove any merges done by the user from the output. How can I do so?

I can check for the commits of a user using git log --author=<name>, but can't remove the merge commits in the output.

PS: Merge conflicts do not happen in the workflow of the repo in question, all branches are rebased before merging into master so it is safe to remove the merge commits from the output, and similarly, two feature branches are not merged with one another raising the possiblity.

Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
  • 2
    What if the merge had a conflict and he had to resolve it? – Joe Phillips Mar 11 '16 at 17:03
  • 2
    @JoePhilllips That doesn't happen in the workflow of the repo in question, all branches are rebased before merging into master. – Anshul Goyal Mar 11 '16 at 17:04
  • 1
    related: [Showing commits made directly to a branch, ignoring merges in Git](http://stackoverflow.com/questions/8527139/showing-commits-made-directly-to-a-branch-ignoring-merges-in-git), [How to do Git Log see only merges to master branch?](http://stackoverflow.com/questions/25986534/how-to-do-git-log-see-only-merges-to-master-branch) – morxa Mar 11 '16 at 17:09
  • Here is my question which is kind of the _opposite_: [How to view a linear `git log` (exclude feature commits), showing only commits to `main` or merges to `main`](https://stackoverflow.com/q/76625363/4561887) – Gabriel Staples Jul 06 '23 at 04:26

3 Answers3

247

use

git log --author=<name> --no-merges

Additionally the --first-parent option may give useful result for you:

--first-parent

Follow only the first parent commit upon seeing a merge commit. This option can give a better overview when viewing the evolution of a particular topic branch, because merges into a topic branch tend to be only about adjusting to updated upstream from time to time, and this option allows you to ignore the individual commits brought in to your history by such a merge. Cannot be combined with --bisect.

Gabriel Staples
  • 36,492
  • 15
  • 194
  • 265
0xAX
  • 20,957
  • 26
  • 117
  • 206
28

You can omit merges with --no-merges:

git log --no-merges --author=<name>

See the git log manpage for details.

morxa
  • 3,221
  • 3
  • 27
  • 43
18

The OP's question has been answered. I expounded on the answer for the lurkers. This lengthy log call will give you a nice view filtered by committer sans merge. Use git alias to tame this if you desire.

I hope it benefits someone and isn't treated too harshly with down-votes.

git log --no-merges --max-count=15 --pretty="format:%C(dim green) %<(9,trunc)%ar %C(bold magenta)%h %C(bold green)%<(12,trunc)%an %C(bold
yellow)%<(113,trunc)%s" --committer="<name>"

Example: enter image description here

Joe Johnston
  • 2,794
  • 2
  • 31
  • 54