git/list[1] front-page[2] threads[3] people[4] search[5] about
 

`git range-diff` lists chunks with uninteresting changes

From
Ssquirrel <jatjasjem@gmail.com>
Date
Aug 20, 2022, 14:51 UTC
Message-ID
<CAAsFbAtu0vYhwa-Kb6dfpNBZ7jSLriVODi1s7H=-Deq9J6L0ww@mail.gmail.com>

When someone makes a PR, they may be asked to rebase their feature branch onto main to resolve conflicts. It may be useful to quickly see what changed during the rebase, that is how the new version of PR is different to the old one.

If the PR branch has not been reparented, you may get away with `git diff`. But if it has, `git diff` may contain a lot of changes from upstream. Instead, `git range-diff` can be used.

The problem with this is that in this case `git range-diff` can show chunks with changes that have nothing to do with changes in the PR. Consider this repository (commands are runnable):

    git init
    git branch -m main
    echo -e "a\nb\nc\nd\ne\n1\n2\n3\nf" > file
    git add file
    git commit -am "a b c d e f"
    git checkout -b foo
    echo -e "a\nb\nc\nd\ne\n1\n2\n3\nfoo" > file
    git commit -am "f -> foo"
    git checkout main
    git checkout -b cat
    echo -e "a\nb\ncat\nd\ne\n1\n2\n3\nf" > file
    git commit -am "c -> cat"

We got a few letters of alphabet on separate lines on main, and in branch foo `f` is changed to `foo`, and in branch cat `c` is changed to `cat`.

    $ git log --all --graph --pretty=oneline
    * 90e873e3 (HEAD -> cat) c -> cat
    | * 3d8c1baf (foo) f -> foo
    |/
    * 4d2337dd (main) a b c d e f
Now, still on cat, let's combine the two changes.
    $ git rebase foo
    Successfully rebased and updated refs/heads/cat
    $ git log --all --graph --pretty=oneline
    * 98e554a0 (HEAD -> cat) c -> cat
    * 3d8c1baf (foo) f -> foo
    * 4d2337dd (main) a b c d e f

Now, `git rebase foo` worked automatically, so *the change* of the last commit on `cat` is the same as it was without rebase, which is changing `c` to `cat`. But if we run `git range-diff`, we will see this:

    $ git range-diff 90e873e3...cat
    -:  ------- > 1:  3d8c1ba f -> foo
    1:  90e873e ! 2:  98e554a c -> cat
        @@ file
         +cat
          d
          e
        - f
        + foo

It seems that this chunk is included for the sole reason that the change from `foo` is sort of close. If we try the same code, but put the lines `c` and `f` further apart, for example by replacing `e\n` with `e\n1\n2\n3\n` in the commands above, the output would be, as expected,

    $ git range-diff f1e0a6cc3...cat
    -:  ------- > 1:  4db06be f -> foo
    1:  f1e0a6c = 2:  cc56db7 c -> cat

I suggest not showing uninteresting chunks like that, or perhaps having a command line option that controls how close together the changes must be in order to be included in the output.

Next: Johannes Schindelin
Message 1 of 3 in “`git range-diff` lists chunks with uninteresting changes”
  1. squirrelAug 20, 2022
  2. Johannes SchindelinAug 22, 2022
  3. squirrelAug 22, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.