efedorenko
efedorenko

Reputation: 31

Summary of changes in several Git commits

I'd like to get a summary of changes in several not consecutive Git commits. Here is an example:

I wish to get a summary like this:

Is it possible? (It's really similar to Compare view in Github.)

Thanks!

Upvotes: 2

Views: 3388

Answers (3)

LinusR
LinusR

Reputation: 1209

I was looking for something similar, except for your 'not consecutive' requirement. I share it in case it helps someone who came here with the same question as me (similar to yours), or in case it helps you come closer to your answer.

I have a feature branch that has diverged from master -- i.e. both branches have new commits since their last common ancestor, and I want to know what changes the feature branch would try to introduce if merged into master.

git diff master feature will not do what I want, because every new change on master since feature branched off will be shown negatively, because feature does not have it. I only want to see the positive work done on feature.

git log --stat master..feature comes closer, by showing me the files changed by each commit on feature since it diverged from master. But it's still hard to use if feature has dozens of new commits.

What I want to see is a "squashed" version of the changes feature branch contains, relative to master, but ignoring the changes made on master since the branching.

Here's what works for me:

# get the commit ID of the last common ancestor
git merge-base feature master

# show the diff from that ancestor to the head of feature branch
# (works with --stat option too, to summarize changes)
git diff <ancestor ID> feature

# combined form:
git diff `git merge-base feature master` feature

Upvotes: 0

Cascabel
Cascabel

Reputation: 496912

Well, you can do something like this:

for c in $commits; do
    echo $c
    git show --name-status $c
    echo
done

And you can script around it to make it fancier and fancier until you get the output format you want. Replace $commits with something like $(git rev-list --author=Me master..topic) to dump in a commit list. Slurp up all the output and regroup it into a per-file list (awk would be good at that). So on and so forth.

Upvotes: 0

kynnysmatto
kynnysmatto

Reputation: 3892

That sounds like git diff to me.

git diff commit1 commit3

This will show file names and lines that have changed between those two commits. If you are using git from command line, I recommend enabling colors. That will make the diff output much easier to read:

git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto

There are also some programs that can visualize the diff output in a graphical way. (Like kompare in Linux for example)

Upvotes: 3

Related Questions