user997112
user997112

Reputation: 30605

git log, show files for specific username and branch

I'd like to combine git log and git show so that I can list all changes files for a given user, for a given branch. My aim is to be able to see what files I have personally changes, over the life of a branch (as opposed to files changes in my branch from a merge)

What is the best way to achieve this?

Upvotes: 3

Views: 361

Answers (2)

Mark Adelsberger
Mark Adelsberger

Reputation: 45659

You can limit log output to a given author and/or committer

git log --author=my_username

You can have log give the history of a branch simply by naming the branch, but be aware this alone may not to exactly what you expect (see below):

git log --author=my_username my_branch

The thing is, this will list all commits reachable from the branch. (A branch is a pointer to a single commit; log then follows "parent commit" pointers (by default) to provide a history for the branch.

That will include commits that, perhaps, you think are "on the parent branch" rather than "on this branch". For example

A -- B -- C -- D <--(master)
      \
       E -- F <--(my_branch)

Here all of A, B, E and F are reachable from my_branch. So if you think of A and B as "not on the branch", you need something more. And what that is depends on the situation, because the idea of commits "on a particular branch" (rather than "reachable from any number of branches") is an artificial concept users like to impose on git, but that git doesn't really know about.

In the above case, you would say

git log --author=my_username master..my_branch

to exclude anything reachable from master, leaving E and F only (and filtering those based on author info).

Lastly, you appear to want to see the patch from each change. (You said "combine with show".) So you could use -p:

git log -p --author=my_username master..my_branch

Or if you decide you'd rather list the files instead

git log --name-only --author=my_username master..my_branch

Upvotes: 3

0x5453
0x5453

Reputation: 13589

This is a git alias that I use; If I understand the question, I think this does what you want.

if $(git rev-parse --verify --quiet $1 >/dev/null); then
    COMMIT=$1;
    shift;
else
    COMMIT=HEAD;
fi;
git log "$@" $(git merge-base origin/master $COMMIT)..$COMMIT;

Usage: git <alias_name> [commit] [extra_args], so I would do git lo --author="John Doe". You can add extra git log arguments like -p and --stat to find the information you are looking for.

Upvotes: 0

Related Questions