172

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.

4

3 Answers 3

283

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.

Sign up to request clarification or add additional context in comments.

6 Comments

even nicer with --pretty=format:"%h%x09%an%x09%ad%x09%s"
@k1eran this truncates the commit body (assuming there's one)
@Erythros understood, and I find it useful to get a concise readable summary of the commits.
Or including colors and graph log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --first-parent
using this command gives you a clean list of changes, then u can take the commits with git cherry-pick <commit> , thanks :D
|
32

You can omit merges with --no-merges:

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

See the git log manpage for details.

1 Comment

This only excludes the merge commits. But the normal commits inside that upstream branch is still visible.
21

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.