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

Re: Optimizing writes to unchanged files during merges?

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Apr 12, 2018, 23:18 UTC
Message-ID
<CA+55aFzNJXMktB1owXtuD=KXEQRcZmdETMJOiv+RcRZv9Pgz7A@mail.gmail.com>
In-Reply-To
<xmqq604w2j4u.fsf@gitster-ct.c.googlers.com>
On Thu, Apr 12, 2018 at 2:46 PM, Junio C Hamano <gitster@pobox.com> wrote:
>
> Thanks for a clear description of the issue.  It does sound
> interesting.

I decided to show it with a simpler case that could be scripted and doesn't need the kernel.

NOTE! This obviously doesn't happen for files with the trivial merge cases (ie the ones that don't require any real merging at all).

There *is* a three-way merge going on, it's just that the end result is the same as the original file.

Example script just appended here at the end.
NOTE: The script uses "ls -l --full-time", which afaik is a GNU ls
extension. So the script below is not portable.
                 Linus
---
  # Create throw-away test repository
  mkdir merge-test
  cd merge-test
  git init
  # Create silly baseline file with 10 lines of numbers in it
  for i in $(seq 1 10); do echo $i; done > a
  git add a
  git commit -m"Original"
  # Make a branch that changes '9' to 'nine'
  git checkout -b branch
  sed -i 's/9/nine/' a
  git commit -m "Nine" a
  # On the master, change '2' to 'two' _and_ '9' to 'nine'
  git checkout master
  sed -i 's/9/nine/' a
  sed -i 's/2/two/' a
  git commit -m "Two and nine" a
  # sleep to show the time difference
  sleep 1
  # show the date on 'a' and do the merge
  ls -l --full-time a
  git merge -m "Merge contents" branch
  # The merge didn't change the contents, but did rewrite the file
  ls -l --full-time a
Previous: Elijah NewrenNext: Elijah Newren
Message 28 of 29 in “Optimizing writes to unchanged files during merges?”
  1. Linus TorvaldsApr 12, 2018
  2. Junio C HamanoApr 12, 2018
  3. Junio C HamanoApr 12, 2018
  4. Linus TorvaldsApr 12, 2018
  5. Linus TorvaldsApr 12, 2018
  6. Linus TorvaldsApr 12, 2018
  7. Linus TorvaldsApr 13, 2018
  8. Elijah NewrenApr 13, 2018
  9. Linus TorvaldsApr 13, 2018
  10. Stefan BellerApr 13, 2018
  11. Linus TorvaldsApr 13, 2018
  12. Elijah NewrenApr 13, 2018
  13. Junio C HamanoApr 13, 2018
  14. Junio C HamanoApr 16, 2018
  15. Linus TorvaldsApr 16, 2018
  16. Lars SchneiderApr 16, 2018
  17. Ævar Arnfjörð BjarmasonApr 16, 2018
  18. Lars SchneiderApr 17, 2018
  19. Jacob KellerApr 16, 2018
  20. Jacob KellerApr 16, 2018
  21. Junio C HamanoApr 16, 2018
  22. Lars SchneiderApr 17, 2018
  23. Jacob KellerApr 17, 2018
  24. Phillip WoodApr 16, 2018
  25. Stefan HallerApr 16, 2018
  26. Elijah NewrenApr 16, 2018
  27. Elijah NewrenApr 16, 2018
  28. Linus TorvaldsApr 12, 2018
  29. Elijah NewrenApr 13, 2018

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.