Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

When I merge branches, I frequently want to get a summary of all the file differences between the branches.

git diff --stat -r branch1..branch2 works great for this, but I want to have author and date from the latest commit that touched that file as well. The output would look something like this:

ChangeColumns.cls                   | Author1 |  2/10/2015 | 95 ++++++++--------------
GiftApprovalController.cls          | Author2 |  2/11/2015 |  2 +-
MassRelationshipCreation.cls        | Author3 |  2/10/2015 |  2 +-
MultiselectedPicklist.cls           | Author4 |  2/08/2015 | 17 ++--
Paginator.cls                       | Author1 |  2/09/2015 | 11 ++-
PipelineManager.cls                 | Author4 |  2/10/2015 |  7 +-
TestSetupUtils.cls                  | Author4 |  2/08/2015 | 13 ++-
PipelineManager.page                | Author2 |  2/07/2015 |  5 +-
TestCoverageJsonData.resource       | Author1 |  2/10/2015 | 10 ++-
9 files changed, 78 insertions(+), 84 deletions(-)

Is there any way to do this?

git diff is pairwise: it compares the commit ID branch1 (try git rev-parse branch to see that ID) with the commit ID branch2. With that in mind, define "latest commit that touched [a] file": we know, based on the diff output, that branch1:ChangeColumn.cls and branch2:ChangeColumn.cls differ; do you want "which of these two ID-qualified files has a later time-stamp" or do you want something else, perhaps not even tied to ID1 and ID2 directly? – torek Feb 10, 2015 at 20:17 (Oops, make that: git rev-parse branch1 and git rev-parse branch2, to see raw commit IDs. The main reason to do this is to understand how branch names just name commit IDs; a secondary reason is that branch names resolve to different IDs over time, as you add new commits to those branches.) – torek Feb 10, 2015 at 20:34 @torek, That's a good point. What I am looking for is the date and author from the source branch. Basically what I would see in the first git log entry for that file. – Greg Grinberg Feb 10, 2015 at 23:17 This is still pretty tricky; pratZ's answer can get you a (or all) committer(s), especially if you add a path-name to the git log command (git log A..B [other args] -- path). However, that may show too much, depending on what you want: suppose that in the A..B set, Bob commits a change to line 50, and then Cindy commits a second change that undoes Bob's change to line 50, so that git diff shows no change to line 50. You'll get both Bob and Cindy here. In any case you will need to write some code, I think. – torek Feb 10, 2015 at 23:57

Though not exactly but git log should get you something closer to what you expect,

git log branch1..branch2 --pretty=format:"%h%x09%an%x09%ad%x09%s"

This will only show you commit differences that branch2 has but branch1doesn't. You will have to reverse it for the getting the commits present in branch1 but not in branch2.

Add a --stat or --name-only to obtain file names

git log branch1..branch2 --pretty=format:"%h%x09%an%x09%ad%x09%s" --stat
                --stat is pretty close to but it's commit oriented rather than file oriented which is what I am trying to get (I know, I am a bad gitter).   I guess I could parse the output of git log but I'm hoping there's a nicer solution.
– Greg Grinberg
                Feb 10, 2015 at 23:39
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.