{"thread":{"id":"57612","subject":"git reset --merge random behavior","startedAt":"2022-03-24T14:50:05Z","lastAt":"2022-03-25T01:58:41Z","messageCount":2,"participants":["Maximilian Reichel","Victoria Dye"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"452119","messageId":"84FF8F9A-3A9A-4F2A-8D8E-5D50F2F06203@icloud.com","threadId":"57612","inReplyTo":null,"subject":"git reset --merge random behavior","fromName":"Maximilian Reichel","fromEmail":"reichemn@icloud.com","sentAt":"2022-03-24T14:43:33Z","receivedAt":"2022-03-24T14:50:05Z","isPatch":false,"sender":{"key":"reichemn@icloud.com","avatar":null},"body":"Thank you for filling out a Git bug report!\nPlease answer the following questions to help us understand your issue.\n\nWhat did you do before the bug happened? (Steps to reproduce your issue)\nRunning the following script (test.sh) multiple times:\n\n ```\n #!/bin/bash\nGIT_TRACE=true\nexport GIT_TRACE\n\nmkdir gitDir0\ncd gitDir0\nenv git -c init.defaultBranch=master init \necho bar > bar.txt\nenv git add -v bar.txt \nenv git -c user.name=\"P\" -c user.email=\"e@mail.com\" commit -v -m first \n\nmkdir ../gitDir2\ncd ../gitDir2\nenv git -c init.defaultBranch=master init \nenv git pull -v --set-upstream ../gitDir0 \necho foo > foo.txt\nenv git add -v foo.txt \nenv git mv -v -f -- foo.txt bar.txt \nenv git reset --merge HEAD\n```\n\nWhat did you expect to happen? (Expected behavior)\nI expect that the script shows the same behavior on every execution.\n\nWhat happened instead? (Actual behavior)\nI encountered two different behaviors (random):\n1. Most of the time the git reset command succeeds and the file gitDir2/bar.txt contains the string \"bar\" after running the script.\n2. Sometimes the git reset command fails and the file gitDir2/bar.txt contains the string \"foo\" after running the script.\nIn this case, the reset command produces the following output:\n```\nerror: Entry 'bar.txt' not uptodate. Cannot merge.\nfatal: Could not reset index file to revision 'HEAD'.\n```\nThe full console output of both cases is attached to this mail, but they only really differ in this error message.\n\nAnything else you want to add:\nI could observe this behavior on git 2.35.1 and 2.34.1.\nThe behavior is not affected by whether GIT_TRACE is set.\n\nI wrote a script that executes this test script repeatedly and keeps track of the possible outcomes of the gitDir2/bar.txt file.\nIt will print a line each time the content differs from the previous execution.\nThis script is attached to this mail (runner.sh).\nSample output of this script:\n```\nexecution #0 \t hash: c157a79031e1c40f85931829bc5fc552 \t date: Thu Mar 24 13:22:17 UTC 2022\nexecution #203 \t hash: d3b07384d113edec49eaa6238ad5ff00 \t date: Thu Mar 24 13:22:29 UTC 2022\nexecution #204 \t hash: c157a79031e1c40f85931829bc5fc552 \t date: Thu Mar 24 13:22:29 UTC 2022\nexecution #264 \t hash: d3b07384d113edec49eaa6238ad5ff00 \t date: Thu Mar 24 13:22:32 UTC 2022\nexecution #265 \t hash: c157a79031e1c40f85931829bc5fc552 \t date: Thu Mar 24 13:22:32 UTC 2022\nexecution #432 \t hash: d3b07384d113edec49eaa6238ad5ff00 \t date: Thu Mar 24 13:22:40 UTC 2022\nexecution #433 \t hash: c157a79031e1c40f85931829bc5fc552 \t date: Thu Mar 24 13:22:40 UTC 2022\nexecution #489 \t hash: d3b07384d113edec49eaa6238ad5ff00 \t date: Thu Mar 24 13:22:43 UTC 2022\n```\n\n\n[System Info]\ngit version:\ngit version 2.35.1\ncpu: x86_64\nbuilt from commit: 4c53a8c20f8984adb226293a3ffd7b88c3f4ac1a\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nuname: Linux 5.10.25-linuxkit #1 SMP Tue Mar 23 09:27:39 UTC 2021 x86_64\ncompiler info: gnuc: 10.2\nlibc info: glibc: 2.31\n$SHELL (typically, interactive shell): <unset>\n\n\n[Enabled Hooks]\nnot run from a git repository - no hooks to show\n\n\n13:05:42.974156 git.c:458               trace: built-in: git init\nwarning: templates not found in /usr/local/share/git-core/templates\nInitialized empty Git repository in /test2/workDir/gitDir0/.git/\n13:05:42.976995 git.c:458               trace: built-in: git add -v bar.txt\nadd 'bar.txt'\n13:05:42.979187 git.c:458               trace: built-in: git commit -v -m first\n13:05:42.980431 run-command.c:654       trace: run_command: git maintenance run --auto --no-quiet\n13:05:42.981375 git.c:458               trace: built-in: git maintenance run --auto --no-quiet\n[master (root-commit) 4165aea] first\n 1 file changed, 1 insertion(+)\n create mode 100644 bar.txt\n13:05:42.984917 git.c:458               trace: built-in: git init\nwarning: templates not found in /usr/local/share/git-core/templates\nInitialized empty Git repository in /test2/workDir/gitDir2/.git/\n13:05:42.987933 git.c:458               trace: built-in: git pull -v --set-upstream ../gitDir0\n13:05:42.988098 run-command.c:654       trace: run_command: git fetch --update-head-ok -v --set-upstream ../gitDir0\n13:05:42.989104 git.c:458               trace: built-in: git fetch --update-head-ok -v --set-upstream ../gitDir0\n13:05:42.989301 run-command.c:654       trace: run_command: unset GIT_PREFIX; GIT_PROTOCOL=version=2 'git-upload-pack '\\''../gitDir0'\\'''\n13:05:42.990794 git.c:458               trace: built-in: git upload-pack ../gitDir0\n13:05:42.991782 run-command.c:654       trace: run_command: git pack-objects --revs --thin --stdout --delta-base-offset\nremote: 13:05:42.992962 git.c:458               trace: built-in: git pack-objects --revs --thin --stdout --delta-base-offset        \n13:05:42.993799 run-command.c:654       trace: run_command: git unpack-objects -q --pack_header=2,3\n13:05:42.995006 git.c:458               trace: built-in: git unpack-objects -q --pack_header=2,3\n13:05:42.995872 run-command.c:654       trace: run_command: git rev-list --objects --stdin --not --all --quiet --alternate-refs\n13:05:42.996906 git.c:458               trace: built-in: git rev-list --objects --stdin --not --all --quiet --alternate-refs\nFrom ../gitDir0\n * branch            HEAD       -> FETCH_HEAD\n13:05:42.998066 run-command.c:1582      run_processes_parallel: preparing to run up to 1 tasks\n13:05:42.998076 run-command.c:1614      run_processes_parallel: done\n13:05:42.998082 run-command.c:654       trace: run_command: git maintenance run --auto --no-quiet\n13:05:42.999099 git.c:458               trace: built-in: git maintenance run --auto --no-quiet\n13:05:43.002592 git.c:458               trace: built-in: git add -v foo.txt\nadd 'foo.txt'\n13:05:43.004882 git.c:458               trace: built-in: git mv -v -f -- foo.txt bar.txt\nwarning: overwriting 'bar.txt'\nRenaming foo.txt to bar.txt\n13:05:43.007057 git.c:458               trace: built-in: git reset --merge HEAD\nerror: Entry 'bar.txt' not uptodate. Cannot merge.\nfatal: Could not reset index file to revision 'HEAD'.\n\n\n13:05:36.550286 git.c:458               trace: built-in: git init\nwarning: templates not found in /usr/local/share/git-core/templates\nInitialized empty Git repository in /test2/workDir/gitDir0/.git/\n13:05:36.553483 git.c:458               trace: built-in: git add -v bar.txt\nadd 'bar.txt'\n13:05:36.555923 git.c:458               trace: built-in: git commit -v -m first\n13:05:36.557265 run-command.c:654       trace: run_command: git maintenance run --auto --no-quiet\n13:05:36.558315 git.c:458               trace: built-in: git maintenance run --auto --no-quiet\n[master (root-commit) aea16b2] first\n 1 file changed, 1 insertion(+)\n create mode 100644 bar.txt\n13:05:36.561756 git.c:458               trace: built-in: git init\nwarning: templates not found in /usr/local/share/git-core/templates\nInitialized empty Git repository in /test2/workDir/gitDir2/.git/\n13:05:36.564497 git.c:458               trace: built-in: git pull -v --set-upstream ../gitDir0\n13:05:36.564679 run-command.c:654       trace: run_command: git fetch --update-head-ok -v --set-upstream ../gitDir0\n13:05:36.565640 git.c:458               trace: built-in: git fetch --update-head-ok -v --set-upstream ../gitDir0\n13:05:36.565830 run-command.c:654       trace: run_command: unset GIT_PREFIX; GIT_PROTOCOL=version=2 'git-upload-pack '\\''../gitDir0'\\'''\n13:05:36.567311 git.c:458               trace: built-in: git upload-pack ../gitDir0\n13:05:36.568164 run-command.c:654       trace: run_command: git pack-objects --revs --thin --stdout --delta-base-offset\nremote: 13:05:36.569156 git.c:458               trace: built-in: git pack-objects --revs --thin --stdout --delta-base-offset        \n13:05:36.570130 run-command.c:654       trace: run_command: git unpack-objects -q --pack_header=2,3\n13:05:36.571443 git.c:458               trace: built-in: git unpack-objects -q --pack_header=2,3\n13:05:36.572322 run-command.c:654       trace: run_command: git rev-list --objects --stdin --not --all --quiet --alternate-refs\n13:05:36.573357 git.c:458               trace: built-in: git rev-list --objects --stdin --not --all --quiet --alternate-refs\nFrom ../gitDir0\n * branch            HEAD       -> FETCH_HEAD\n13:05:36.574654 run-command.c:1582      run_processes_parallel: preparing to run up to 1 tasks\n13:05:36.574663 run-command.c:1614      run_processes_parallel: done\n13:05:36.574669 run-command.c:654       trace: run_command: git maintenance run --auto --no-quiet\n13:05:36.575573 git.c:458               trace: built-in: git maintenance run --auto --no-quiet\n13:05:36.578926 git.c:458               trace: built-in: git add -v foo.txt\nadd 'foo.txt'\n13:05:36.581235 git.c:458               trace: built-in: git mv -v -f -- foo.txt bar.txt\nwarning: overwriting 'bar.txt'\nRenaming foo.txt to bar.txt\n13:05:36.583892 git.c:458               trace: built-in: git reset --merge HEAD\n"},{"id":"452254","messageId":"6cb5414a-e1d0-bbfe-3744-f6df5dbb0db5@github.com","threadId":"57612","inReplyTo":"84FF8F9A-3A9A-4F2A-8D8E-5D50F2F06203@icloud.com","subject":"Re: git reset --merge random behavior","fromName":"Victoria Dye","fromEmail":"vdye@github.com","sentAt":"2022-03-25T01:58:34Z","receivedAt":"2022-03-25T01:58:41Z","isPatch":false,"sender":{"key":"vdye@github.com","avatar":"https://avatars.githubusercontent.com/u/3619353?v=4"},"body":"Maximilian Reichel wrote:\n> Thank you for filling out a Git bug report!\n> Please answer the following questions to help us understand your issue.\n> \n> What did you do before the bug happened? (Steps to reproduce your issue)\n> Running the following script (test.sh) multiple times:\n> \n>  ```\n>  #!/bin/bash\n> GIT_TRACE=true\n> export GIT_TRACE\n> \n> mkdir gitDir0\n> cd gitDir0\n> env git -c init.defaultBranch=master init \n> echo bar > bar.txt\n> env git add -v bar.txt \n> env git -c user.name=\"P\" -c user.email=\"e@mail.com\" commit -v -m first \n> \n> mkdir ../gitDir2\n> cd ../gitDir2\n> env git -c init.defaultBranch=master init \n> env git pull -v --set-upstream ../gitDir0 \n> echo foo > foo.txt\n> env git add -v foo.txt \n> env git mv -v -f -- foo.txt bar.txt \n> env git reset --merge HEAD\n> ```\n> \n> What did you expect to happen? (Expected behavior)\n> I expect that the script shows the same behavior on every execution.\n> \n> What happened instead? (Actual behavior)\n> I encountered two different behaviors (random):\n> 1. Most of the time the git reset command succeeds and the file gitDir2/bar.txt contains the string \"bar\" after running the script.\n> 2. Sometimes the git reset command fails and the file gitDir2/bar.txt contains the string \"foo\" after running the script.\n> In this case, the reset command produces the following output:\n> ```\n> error: Entry 'bar.txt' not uptodate. Cannot merge.\n> fatal: Could not reset index file to revision 'HEAD'.\n> ```\n> The full console output of both cases is attached to this mail, but they only really differ in this error message.\n> \n\nI was able to reliably reproduce both the success and failure scenarios with\na slightly simplified script:\n\n# Setup\n$ git init test-repo\n$ cd test-repo\n$ echo bar >bar.txt\n$ git commit -am first\n\n# Succeeds\n$ echo foo >foo.txt\n$ git add foo.txt\n$ git mv -f foo.txt bar.txt\n$ git update-index --refresh\n$ git reset --merge HEAD\n\n# Fails\n$ echo foo >foo.txt\n$ git mv -f foo.txt bar.txt\n$ git reset --merge HEAD\n\nIt looks like the error happens because 'mv' doesn't refresh the\n\"up-to-date\" flag on 'bar.txt', so the subsequent 'reset --merge' thinks\nthere's a conflict that doesn't actually exist. \n\nI've submitted a patch [1] to fix this permanently, but if you need a\nworkaround in the meantime, you can call 'git update-index --refresh' after\n'git mv' to avoid the error.\n\n[1] https://lore.kernel.org/git/pull.1187.git.1648173419533.gitgitgadget@gmail.com/\n\n> Anything else you want to add:\n> I could observe this behavior on git 2.35.1 and 2.34.1.\n> The behavior is not affected by whether GIT_TRACE is set.\n> \n> I wrote a script that executes this test script repeatedly and keeps track of the possible outcomes of the gitDir2/bar.txt file.\n> It will print a line each time the content differs from the previous execution.\n> This script is attached to this mail (runner.sh).\n> Sample output of this script:\n> ```\n> execution #0 \t hash: c157a79031e1c40f85931829bc5fc552 \t date: Thu Mar 24 13:22:17 UTC 2022\n> execution #203 \t hash: d3b07384d113edec49eaa6238ad5ff00 \t date: Thu Mar 24 13:22:29 UTC 2022\n> execution #204 \t hash: c157a79031e1c40f85931829bc5fc552 \t date: Thu Mar 24 13:22:29 UTC 2022\n> execution #264 \t hash: d3b07384d113edec49eaa6238ad5ff00 \t date: Thu Mar 24 13:22:32 UTC 2022\n> execution #265 \t hash: c157a79031e1c40f85931829bc5fc552 \t date: Thu Mar 24 13:22:32 UTC 2022\n> execution #432 \t hash: d3b07384d113edec49eaa6238ad5ff00 \t date: Thu Mar 24 13:22:40 UTC 2022\n> execution #433 \t hash: c157a79031e1c40f85931829bc5fc552 \t date: Thu Mar 24 13:22:40 UTC 2022\n> execution #489 \t hash: d3b07384d113edec49eaa6238ad5ff00 \t date: Thu Mar 24 13:22:43 UTC 2022\n> ```\n> \n> \n> [System Info]\n> git version:\n> git version 2.35.1\n> cpu: x86_64\n> built from commit: 4c53a8c20f8984adb226293a3ffd7b88c3f4ac1a\n> sizeof-long: 8\n> sizeof-size_t: 8\n> shell-path: /bin/sh\n> uname: Linux 5.10.25-linuxkit #1 SMP Tue Mar 23 09:27:39 UTC 2021 x86_64\n> compiler info: gnuc: 10.2\n> libc info: glibc: 2.31\n> $SHELL (typically, interactive shell): <unset>\n> \n> \n> [Enabled Hooks]\n> not run from a git repository - no hooks to show\n\n"}]}