4

I have read the manual for git diff here http://git-scm.com/docs/git-diff and I did not find an answer.

I'm using git diff origin/master according to this format git diff [--options] <commit> <commit> [--] [<path>…](omitted commit == HEAD) after a git fetch to see what changes have been done before I do my git merge origin/master.

It's realy usefull and I can review the code before applying the changes. My only problem is that I'm working in a team and I want to know which commiter did the change on every file.

I did not find any option of git diff that show the committer. What's the easiest way to see the committer (if possible with git diff)

EDIT :

I see that my question was not detailled enough.

For example, when I do a git diff I get:

--- a/path/to/my/file.html
+++ b/path/to/my/file.html
@@ -xx,y +xx,y @@
-      {% if sett.value|lower != "false" %}
+      {% if sett.value|lower != False %}

So I know that someone change this line and commit it. Idealy I want to have something like :

User John Doe commit the following :
--- a/path/to/my/file.html
+++ b/path/to/my/file.html
@@ -xx,y +xx,y @@
-      {% if sett.value|lower != "false" %}
+      {% if sett.value|lower != False %}
Laurent
  • 1,710
  • 4
  • 25
  • 46
  • 1
    FYI: _committer_ and _author_ are two different things in git terminology. I believe OP refers to commit authors, not committers. More info is [here](https://stackoverflow.com/a/18754896). Use `git log --format=fuller -p` to check the history of the current branch with both authors and committers, including the code. Of course, there are multiple ways to achieve the same with other tools or git commands (`tig` would be another example). – Andrejs Cainikovs Jul 21 '22 at 12:14

3 Answers3

3

Simplest way to obtain the committer of the latest commit in origin/master is to use git log:

git log -1 origin/master

-1 instructs git log to only show one commit of origin/master

Starting from here, you could set up an alias for a tweaked git log, for example using this:

git log -1 --pretty=format:"%an (%ae)" origin/master

will print <Author Name> (<Author E-Mail>).

See the docs of git log for more information about formatting the output, for adding an alias, trust SO: How do I alias commands in git?

Community
  • 1
  • 1
eckes
  • 64,417
  • 29
  • 168
  • 201
2

git diff is probably not the tool you want if you're looking to find out who modified certain lines of code.

You could try using git blame which "annotates each line in the given file with information from the revision which last modified the line".

EDIT: If you're in the situation described in your comment where you have done git fetch and want to see the committers of any commits that you haven't yet merged in, then you can use git log <remote>/<branch_name>. You could then limit the output to the number of commits that origin is ahead by, for example git log -2 origin/master would let you find out the committers of the 2 commits that you have not yet merged into your local master branch.

EDIT2: Try git show, which for commits "shows the log message and textual diff" (including the committer). It works on a single commit, so you will need to specify which one you want to look at, there are many ways to do this such as getting the commit hash, using syntax such as origin/master^, etc.

Adam H
  • 1,523
  • 11
  • 21
  • Yes I know about git blame, but it shows every line. I just want to know the committer of the last modification. – Laurent Oct 14 '14 at 12:42
  • Sorry I don't entirely understand. Do you only want to see the committers who most recently modified the lines you have changed? – Adam H Oct 14 '14 at 12:53
  • I only want to see the committers who did the commit that is not yet merged with my local branch. I.E. I do git fetch, there is for example 2 commit I did not merge with, I want to see who did the commits with git diff – Laurent Oct 14 '14 at 13:53
1

Presuming you are on a tracking branch then you can do

 git log HEAD..@{u} -p

You can tweak the arguments to log to display exactly the information that you want if the defaults don't suit you, but that should be pretty close to what you want. To explicitly show the committer you could use --pretty=fuller or add %cn and/or %ce to your pretty format to specify the committer name and email respectively.

Of you aren't using a tracking branch then replace @{u} with branch you want to merge from (origin/master)

Andrew C
  • 13,845
  • 6
  • 50
  • 57