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

Strange effect merging empty file

From
RNRalf Nyren <ralf.nyren@ericsson.com>
Date
Mar 21, 2012, 10:28 UTC
Message-ID
<4F69AD3C.4070203@ericsson.com>
Hi,

I found a "strange effect" when merging from a branch containing a change of a previously empty file. The change is added to another empty file in the current branch by the merge.

I guess git sees it as a renamed file which is logical from a content-perspective.

Not sure what to do with this, I would not say it is a bug really...
Reproduce as follows (should be cut-n-paste friendly):

# Start with a new repository git init echo 'Readme file' > README git add README git commit -m 'Initial commit'

# Setup the branch to be merged git checkout -b import touch empty.txt echo hello world > hello.txt git add empty.txt hello.txt git commit -m 'Import 1.0' git tag IMPORT_1.0 echo This file is no longer empty > empty.txt git commit -m 'Import 1.1' empty.txt git tag IMPORT_1.1

# Setup master branch git checkout master mkdir static touch static/.gitignore git add static/.gitignore git commit -m 'Static web content'

# Merge import 1.0 and remove the empty file git merge IMPORT_1.0 git rm empty.txt git commit -m 'Remove empty file' empty.txt

# Merge import 1.1 and watch empty.txt contents show up in .gitignore git merge IMPORT_1.1 cat static/.gitignore

regards, Ralf
Next: Zbigniew Jędrzejewski-Szmek
Message 1 of 25 in “Strange effect merging empty file”
  1. Ralf NyrenMar 21, 2012
  2. Zbigniew Jędrzejewski-SzmekMar 21, 2012
  3. Junio C HamanoMar 21, 2012
  4. Randal L. SchwartzMar 22, 2012
  5. Ralf NyrenMar 22, 2012
  6. Zbigniew Jędrzejewski-SzmekMar 22, 2012
  7. Jeff KingMar 22, 2012
  8. Junio C HamanoMar 22, 2012
  9. Jeff KingMar 22, 2012
  10. Jeff KingMar 22, 2012
  11. Jeff KingMar 22, 2012
  12. 1/3 drop casts from users EMPTY_TREE_SHA1_BINJeff King, Mar 22, 2012
  13. 2/3 make is_empty_blob_sha1 available everywhereJeff King, Mar 22, 2012
  14. 3/3 merge-recursive: don't detect renames from empty filesJeff King, Mar 22, 2012
  15. Jonathan NiederMar 22, 2012
  16. Jeff KingMar 22, 2012
  17. Junio C HamanoMar 22, 2012
  18. Jeff KingMar 22, 2012
  19. Junio C HamanoMar 22, 2012
  20. 0/2 merging renames of empty filesJeff King, Mar 22, 2012
  21. 1/2 teach diffcore-rename to optionally ignore empty contentJeff King, Mar 22, 2012
  22. 2/2 merge-recursive: don't detect renames of empty filesJeff King, Mar 22, 2012
  23. Junio C HamanoMar 22, 2012
  24. Jeff KingMar 23, 2012
  25. Junio C HamanoMar 23, 2012

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.