git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
* git-log on a file, and merges
@ 2019-08-02  9:38 Piotr Krukowiecki
  2019-08-02 14:22 ` Derrick Stolee
  0 siblings, 1 reply; 5+ messages in thread
From: Piotr Krukowiecki @ 2019-08-02  9:38 UTC (permalink / raw)
  To: Git Mailing List

Hi,

I have merged a branch into master.

When on master I do "git log -- some/file", it does not show commits
from merged branch (which I know they changed the file).
I have to add "--full-history" to see the commits.
When I run "git log" (without "-- some/file") I can see the commits
without using "--full-history".

This seems not logical, and contrary to user expectations. Harmful even ;)

Am I missing something?

git version 2.22.0.rc1.windows.1

Thanks
-- 
Piotr Krukowiecki

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: git-log on a file, and merges
  2019-08-02  9:38 git-log on a file, and merges Piotr Krukowiecki
@ 2019-08-02 14:22 ` Derrick Stolee
  2019-08-02 19:21   ` Piotr Krukowiecki
  0 siblings, 1 reply; 5+ messages in thread
From: Derrick Stolee @ 2019-08-02 14:22 UTC (permalink / raw)
  To: Piotr Krukowiecki, Git Mailing List

On 8/2/2019 5:38 AM, Piotr Krukowiecki wrote:
> Hi,
> 
> I have merged a branch into master.
> 
> When on master I do "git log -- some/file", it does not show commits
> from merged branch (which I know they changed the file).
> I have to add "--full-history" to see the commits.
> When I run "git log" (without "-- some/file") I can see the commits
> without using "--full-history".
> 
> This seems not logical, and contrary to user expectations. Harmful even ;)
> 
> Am I missing something?

Hi Piotr,

You are falling victim to an issue related to file history simplification [1]
and a (probably) bad merge. You can read more about how this can happen at [2].

When git log reaches a merge commit and one of the parents matches that path
exactly, only that parent is walked. The other is ignored. In some sense, the
other commit did not contribute changes to that file (because we only took
changes from the other parent). This makes the history look good and enables
some performance boosts.

Basically, someone must have gotten a merge conflict and used "-S ours" to
wipe away the changes from the other branch on that file. You can find that
merge by running

	git log --full-history --simplify-merges -- some/file

You will see the merge commit that un-did the change somewhere above the
commit you are expecting to see in the history.

Thanks,
-Stolee


[1] https://git-scm.com/docs/git-log#_history_simplification
[2] https://docs.microsoft.com/en-us/azure/devops/repos/git/git-log-history-simplification?view=azure-devops


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: git-log on a file, and merges
  2019-08-02 14:22 ` Derrick Stolee
@ 2019-08-02 19:21   ` Piotr Krukowiecki
  2019-08-02 19:32     ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Piotr Krukowiecki @ 2019-08-02 19:21 UTC (permalink / raw)
  To: Derrick Stolee; +Cc: Git Mailing List

On Fri, Aug 2, 2019 at 4:22 PM Derrick Stolee <stolee@gmail.com> wrote:
>
> On 8/2/2019 5:38 AM, Piotr Krukowiecki wrote:
> > Hi,
> >
> > I have merged a branch into master.
> >
> > When on master I do "git log -- some/file", it does not show commits
> > from merged branch (which I know they changed the file).
> > I have to add "--full-history" to see the commits.
> > When I run "git log" (without "-- some/file") I can see the commits
> > without using "--full-history".
> >
> > This seems not logical, and contrary to user expectations. Harmful even ;)
> >
> > Am I missing something?
>
> Hi Piotr,
>
> You are falling victim to an issue related to file history simplification [1]
> and a (probably) bad merge. You can read more about how this can happen at [2].
>
> When git log reaches a merge commit and one of the parents matches that path
> exactly, only that parent is walked. The other is ignored. In some sense, the
> other commit did not contribute changes to that file (because we only took
> changes from the other parent). This makes the history look good and enables
> some performance boosts.
>
> Basically, someone must have gotten a merge conflict and used "-S ours" to
> wipe away the changes from the other branch on that file. You can find that
> merge by running
>
>         git log --full-history --simplify-merges -- some/file
>
> You will see the merge commit that un-did the change somewhere above the
> commit you are expecting to see in the history.
>
> Thanks,
> -Stolee
>
>
> [1] https://git-scm.com/docs/git-log#_history_simplification
> [2] https://docs.microsoft.com/en-us/azure/devops/repos/git/git-log-history-simplification?view=azure-devops

Thanks for explaining.

There was no "bad" merge. The file was modified only on the branch
(and previously in common history).

There were two commits to this file on the branch, older one did some
changes, later one reverted the changes (among other things).

So my understanding is that git looked at the merge commit, saw that
this file was the same as it was before the merge, and assumed that
there were no commits which modified this file in the branches being
merged, so it didn't bother looking at the branch history.

At this moment I'm not sure myself if I consider this a bug or not.
Maybe if I look at merge commits as a special entity - not a diverging
history, but rather a single commit which introduces some changes -
then maybe I could accept it.
But on the other hand I feel this generates wrong results. Falsifies
history. If I was asking about "diff", I would understand if it showed
nothing, as there was no difference. But I'm asking for "log".
Especially that I remembered/checked that there were some changes to
this file, and wanted to see them.


Anyway, is there a way to disable this behavior (enable
"--full-history"?) by default?
I suspect that this behavior will bite me in future, and I guess the
"performance gains" are not big enough to validate it...



-- 
Piotr Krukowiecki

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: git-log on a file, and merges
  2019-08-02 19:21   ` Piotr Krukowiecki
@ 2019-08-02 19:32     ` Junio C Hamano
  2019-08-03  8:31       ` Piotr Krukowiecki
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2019-08-02 19:32 UTC (permalink / raw)
  To: Piotr Krukowiecki; +Cc: Derrick Stolee, Git Mailing List

Piotr Krukowiecki <piotr.krukowiecki@gmail.com> writes:

> At this moment I'm not sure myself if I consider this a bug or not.

This definitely is not a bug but is a designed and intended
behaviour.

Think of running "git log" without "--full-history" that is limited
with a pathspec as a tool to ask Git to show _one_ way (preferrably
the simplest one) to explain how the current contents in paths that
match the pathspec came to be.  The "just explain to me one way" is
not about machine performance but reducing the clutter in the output
to help human reader(s) reading an otherwise complex history.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: git-log on a file, and merges
  2019-08-02 19:32     ` Junio C Hamano
@ 2019-08-03  8:31       ` Piotr Krukowiecki
  0 siblings, 0 replies; 5+ messages in thread
From: Piotr Krukowiecki @ 2019-08-03  8:31 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Derrick Stolee, Git Mailing List

On Fri, Aug 2, 2019 at 9:32 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Piotr Krukowiecki <piotr.krukowiecki@gmail.com> writes:
>
> > At this moment I'm not sure myself if I consider this a bug or not.
>
> This definitely is not a bug but is a designed and intended
> behaviour.

(generally speaking)
By "bug" I mean wrong behaviour. Designs can be buggy too.


> Think of running "git log" without "--full-history" that is limited
> with a pathspec as a tool to ask Git to show _one_ way (preferrably
> the simplest one) to explain how the current contents in paths that
> match the pathspec came to be.  The "just explain to me one way" is
> not about machine performance but reducing the clutter in the output
> to help human reader(s) reading an otherwise complex history.

From this point of view, the current behavior is good.

Although it's inconsistent. It works only for merges. If I'm on one
branch and change a file and then revert the change, "git log -- file"
will still show the commits. From your explanation, I'd expect those
commits to be skipped, since they are "no-op".


Also, I did read git-log docs before posting here, but still could not
find clear explanation for this behavior. Is it possible to improve
docs?

For example:

    [--] <path>…
    Show only commits that are enough to explain how the files that
match the specified paths came to be. See History Simplification below
for details and other simplification modes.

For me, the commits which modify the file are relevant to "how the
file come to be". They show what was tried and that finally the
original solution was choosen as the best. So not showing them is not
"enough to explain".
Also "History Simplification" is not very clear.

So maybe something like this? (just a rfc)


diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt
index b406bc4c48..bfb3d68b8b 100644
--- a/Documentation/git-log.txt
+++ b/Documentation/git-log.txt
@@ -91,9 +91,10 @@ include::line-range-format.txt[]
        section of linkgit:gitrevisions[7].

 [--] <path>...::
        Show only commits that are enough to explain how the files
-       that match the specified paths came to be.  See 'History
+       that match the specified paths came to be. Some commits may be
+       not shown even if they modify the specified paths. See 'History
        Simplification' below for details and other simplification
        modes.
 +
 Paths may need to be prefixed with `--` to separate them from
diff --git a/Documentation/rev-list-options.txt
b/Documentation/rev-list-options.txt
index bb1251c036..d2de33b219 100644
--- a/Documentation/rev-list-options.txt
+++ b/Documentation/rev-list-options.txt
@@ -317,13 +317,15 @@ endif::git-rev-list[]
 History Simplification
 ~~~~~~~~~~~~~~~~~~~~~~

 Sometimes you are only interested in parts of the history, for example the
-commits modifying a particular <path>. But there are two parts of
-'History Simplification', one part is selecting the commits and the other
-is how to do it, as there are various strategies to simplify the history.
+commits modifying a particular <path>. This is a two-step process:

-The following options select the commits to be shown:
+* initialial list of commits is selected
+
+* the list is simplified - some commits may be not shown
+
+The following options select the initial list of commits:

 <paths>::
        Commits modifying the given <paths> are selected.

@@ -337,9 +339,11 @@ The following options affect the way the
simplification is performed:
 Default mode::
        Simplifies the history to the simplest history explaining the
        final state of the tree. Simplest because it prunes some side
        branches if the end result is the same (i.e. merging branches
-       with the same content)
+       with the same content). This may happen for example when there
+       were commits which changed files, but then those changes were
+       reverted. Such commits will not be shown.

 --full-history::
        Same as the default mode, but does not prune some history.


-- 
Piotr Krukowiecki

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-08-03  8:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-02  9:38 git-log on a file, and merges Piotr Krukowiecki
2019-08-02 14:22 ` Derrick Stolee
2019-08-02 19:21   ` Piotr Krukowiecki
2019-08-02 19:32     ` Junio C Hamano
2019-08-03  8:31       ` Piotr Krukowiecki

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).