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

Re: Lost file after git merge

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jul 28, 2022, 12:17 UTC
Message-ID
<220728.865yjhl8wk.gmgdl@evledraar.gmail.com>
In-Reply-To
<HE1PR0501MB24096E2FBDB66318A2FDADAAF8969@HE1PR0501MB2409.eurprd05.prod.outlook.com>
On Thu, Jul 28 2022, Laďa Tesařík wrote:
Show 18 quoted lines
> 1. I added a file called 'new_file' to a master branch.
> 2. Then I created branch feature/2 and deleted the file in master
> 3. Then I deleted the file in branch feature/2 as well.
> 4. I created 'new_file' on branch feature/2 again.
> 5. I merged feature/2 into master, merge introduced no changes, file 'new_file' is not present in master.
>
> This could cause problems to our team in the future, fortunately we noticed it this time.
> Please, does anybody have any explanation for this behavior?
>
> Or is anybody aware of any Git or Source option that changes this behaviour?
>
> Thank you very much,
>
> Lada Tesarik
>
> P. S.
> In the picture the steps were done with git revert command, but result is the same if I delete file manually and perform git commit.
> Tested with git versions 2.26 and 2.37

Those who know "merge" better will chime in, but I believe this is known behavior, and you can see why if your "topic" branch doesn't (re)introduce the file as it was on master, but adds a small change to it.

I quickly experimented with this (with the fast-export stream at the end). If you had a "hello" as the content on "master" and introduced "hello2" on the topic you'd get:

	$ git merge topic
	CONFLICT (modify/delete): file.txt deleted in HEAD and modified in topic.  Version topic of file.txt left in tree.
	Automatic merge failed; fix conflicts and then commit the result.

So others will know better, but I vaguely recall this having to do with this being the same in your version (not the below hello2 version, but if you s/hello2/hello/):

	git rev-parse $(git merge-base topic master):
	git rev-parse topic:

I.e. the topic is the TREESAME as its divergence point with "master", which IIRC is a shortcut the merge takes when deciding what changes to keep, and whether they conflict.

-- blob mark :1 data 6 hello

reset refs/heads/master commit refs/heads/master mark :2 author Ævar Arnfjörð Bjarmason <avarab@gmail.com> 1659010359 +0200 committer Ævar Arnfjörð Bjarmason <avarab@gmail.com> 1659010359 +0200 data 9 Add file M 100644 :1 file.txt

commit refs/heads/master mark :3 author Ævar Arnfjörð Bjarmason <avarab@gmail.com> 1659010437 +0200 committer Ævar Arnfjörð Bjarmason <avarab@gmail.com> 1659010437 +0200 data 81 Revert "Add file"

This reverts commit 75aa73c55b19219d47dfc7ec3883c88466678718. from :2 D file.txt

commit refs/heads/topic mark :4 author Ævar Arnfjörð Bjarmason <avarab@gmail.com> 1659010369 +0200 committer Ævar Arnfjörð Bjarmason <avarab@gmail.com> 1659010369 +0200 data 81 Revert "Add file"

This reverts commit 75aa73c55b19219d47dfc7ec3883c88466678718. from :2 D file.txt

blob mark :5 data 7 hello2

commit refs/heads/topic mark :6 author Ævar Arnfjörð Bjarmason <avarab@gmail.com> 1659010359 +0200 committer Ævar Arnfjörð Bjarmason <avarab@gmail.com> 1659010644 +0200 data 9 Add file from :4 M 100644 :5 file.txt

Previous: Laďa TesaříkNext: Junio C Hamano
Message 2 of 9 in “Lost file after git merge”
  1. Laďa TesaříkJul 28, 2022
  2. Ævar Arnfjörð BjarmasonJul 28, 2022
  3. Junio C HamanoJul 28, 2022
  4. René ScharfeJul 29, 2022
  5. Junio C HamanoJul 29, 2022
  6. Elijah NewrenJul 30, 2022
  7. René ScharfeJul 30, 2022
  8. Elijah NewrenJul 31, 2022
  9. brian m. carlsonJul 28, 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.