Re: Seeing git history of file including merge changes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Sep 09, 2015 at 11:26:47AM +0300, Dov Grobgeld wrote:

> The file was changed in commit B and the changes were undone in commit M.
> 
> My problem is how to view the changes to the file between a specific
> commit, e.g. B and another commit in its "downstream", e.g. H.
> 
> If you do
> 
>     git log -u B..H
> 
> you won't see any changes, as the changes due to M are suppressed. You
> can see potential changes by doing:
> 
>     git log -u --full-history B..H
> 
> which will show you that there was a merge commit, but it still won't
> show you the diff between B and M.
> 
> So is there a way of seeing all changes made to a file including those
> made by a merge commit?

Try adding "-m". Normally for merges we show nothing, or the combined
diff. In the latter case, we consider a file which matches one of its
parents to be an uninteresting change. From the perspective of walking
back through history, as git-log does, it is impossible to know whether
B made a change that was thrown away in the merge, or whether A made a
change that we kept. You can only know the answer by walking further
back to the merge-base.

Using "-m" will show you the individual diff against each parent. But
since it is limited by the pathspec, it will show you only the diff
against "B" in this case, which is what you want.  Using this recipe to
recreate your setup:

    # a boring history with a file...
    git init
    echo base >file
    git add file
    git commit -m base
    
    # and some other commits...
    echo foo >unrelated
    git add unrelated
    git commit -m unrelated
    
    # meanwhile, somebody forked from us and changed the file...
    git checkout -b other HEAD^
    echo change >>file && git commit -am change
    
    # now let's merge it in, undoing the change
    git checkout master
    git merge --no-commit other
    echo base >file
    git add file
    git commit -m merged

I get:

    $ git log -p -m --full-history file
    commit a279eccbb7cbb806dceff4591a1d4be74b060645 (from 36d29fbf1caf762ef2d78e484bfc1287a9df7603)
    Merge: 2d1e518 36d29fb
    Author: Jeff King <peff@xxxxxxxx>
    Date:   Wed Sep 9 04:47:26 2015 -0400
    
        merged
    
    diff --git a/file b/file
    index 09025f9..df967b9 100644
    --- a/file
    +++ b/file
    @@ -1,2 +1 @@
     base
    -change

    [...and so on, showing "change" and "base" as you'd expect]

That's pretty good, though if you had other merges in your log output, I
expect "-m" would be messy and confusing there.

So I think what you _really_ want is to recompute the original merge and
show something more clever. There is an old topic, tr/remerge-diff,
which tried to do this. Its output looks the same as what is above, but
it would probably do a better job of not making all of the _other_
merges look ugly.

Unfortunately, development stalled on the topic, and it is nowhere close
to being merged. I can dig up pointers if you'd like to play with it.

-Peff
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]