{"thread":{"id":"62441","subject":"Git revert cannot be aborted if the repository directory has been copied","startedAt":"2024-11-03T01:25:16Z","lastAt":"2024-11-07T19:52:57Z","messageCount":8,"participants":["Marco Stephan","Junio C Hamano","Kristoffer Haugsbakk","Phillip Wood"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"506489","messageId":"AM0PR02MB4980D186BDC087336C760132E6502@AM0PR02MB4980.eurprd02.prod.outlook.com","threadId":"62441","inReplyTo":null,"subject":"Git revert cannot be aborted if the repository directory has been copied","fromName":"Marco Stephan","fromEmail":"marc.stephan96@hotmail.de","sentAt":"2024-11-03T01:25:12Z","receivedAt":"2024-11-03T01:25:16Z","isPatch":false,"sender":{"key":"marc.stephan96@hotmail.de","avatar":null},"body":"Hello,\n\nI have encountered the following bug:\nIf you copy a Git repository directory to another path while there is a revert in progress for the Git repository, \"git revert --abort\" does not work anymore for the copied repository. Instead, it will report an error of the following format:\n      error: Entry '...' not uptodate. Cannot merge.\n      fatal: Could not reset index file to revision '...'.\n\nI can reproduce the bug consistently with the latest version of Git that is available for Windows (git version 2.47.0.windows.2) by performing the following steps (all command line except step 12):\n1. mkdir test_repo\n2. cd test_repo\n3. git init\n4. type nul > test.txt\n5. git add .\n6. git commit -m \"Initial commit\"\n7. echo test > test.txt\n8. git add .\n9. git commit -m \"Changes\"\n10. git revert HEAD --no-commit\n11. cd ..\n12. Manually copy test_repo to a new directory test_repo_copy using the file explorer (using e.g. \"robocopy test_repo test_repo_copy /E\" does not corrupt the repository)\n13. cd test_repo_copy\n14. git revert --abort\nThis consistently produces the error \"error: Entry 'test.txt' not uptodate. Cannot merge.\". I would expect step 14 to work regardless of how the repository directory itself has been created. Running \"git status\" or \"git update --really-refresh\" fixes the seemingly corrupt data and the revert in progress can be aborted.\n\nI have not verified if the bug is present on other operation systems, too.\n\nWith best regards\nMarco Stephan"},{"id":"506490","messageId":"xmqqo72xxcxo.fsf@gitster.g","threadId":"62441","inReplyTo":"AM0PR02MB4980D186BDC087336C760132E6502@AM0PR02MB4980.eurprd02.prod.outlook.com","subject":"Re: Git revert cannot be aborted if the repository directory has been copied","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-11-03T02:34:43Z","receivedAt":"2024-11-03T02:34:45Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Marco Stephan <marc.stephan96@hotmail.de> writes:\n\n> If you copy a Git repository directory to another path while there is a revert in progress for the Git repository, \"git revert --abort\" does not work anymore for the copied repository. Instead, it will report an error of the following format:\n>       error: Entry '...' not uptodate. Cannot merge.\n>       fatal: Could not reset index file to revision '...'.\n\nI wonder if\n\n    $ git update-index --refresh\n\nis all it takes.  The symptom, i.e. Git declares that an otherwise\nunmodifed path is not uptodate, is not limited to \"revert\" or\naborting it, but is a common thing a newbie sees after copyihg a\nworking tree to elsewhere, and \"refresh the index\" is an often given\nrecovery procedure for such a situation.\n\nI'll not comment if this is a bug or not, and let others argue.\n\n"},{"id":"506494","messageId":"9fd66b8f-c457-451b-9862-6121128b2786@app.fastmail.com","threadId":"62441","inReplyTo":"xmqqo72xxcxo.fsf@gitster.g","subject":"Re: Git revert cannot be aborted if the repository directory has been copied","fromName":"Kristoffer Haugsbakk","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2024-11-03T15:04:11Z","receivedAt":"2024-11-03T15:04:33Z","isPatch":false,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"On Sun, Nov 3, 2024, at 03:34, Junio C Hamano wrote:\n> Marco Stephan <marc.stephan96@hotmail.de> writes:\n>\n>> If you copy a Git repository directory to another path while there is a revert in progress for the Git repository, \"git revert --abort\" does not work anymore for the copied repository. Instead, it will report an error of the following format:\n>>       error: Entry '...' not uptodate. Cannot merge.\n>>       fatal: Could not reset index file to revision '...'.\n>\n> I wonder if\n>\n>     $ git update-index --refresh\n>\n> is all it takes.\n\n\nThis is correct.  This successful test can be added to\nt3501-revert-cherry-pick.sh:\n\n```\ntest_expect_success 'cp -r repo in the middle of a revert' '\n\ttest_when_finished rm -r new-repo &&\n\ttest_when_finished rm -r copy-repo &&\n\ttest_create_repo new-repo &&\n\t(\n\t\tcd new-repo &&\n\t\techo nul >test.txt &&\n\t\tgit add test.txt &&\n\t\tgit commit -m \"Initial commit\" &&\n\t\techo test >test.txt &&\n\t\tgit add test.txt &&\n\t\tgit commit -m \"Changes\" &&\n\t\tgit revert HEAD --no-commit\n\t) &&\n\tcp -r new-repo copy-repo &&\n\t(\n\t\tcd copy-repo &&\n\t\t# Needed in order to avoid\n\t\t#     error: Entry test.txt not uptodate. Cannot merge.\n\t\tgit update-index --refresh &&\n\t\tgit revert --abort\n\t)\n'\n```\n\n-- \nKristoffer Haugsbakk\n"},{"id":"506495","messageId":"bb6d781e-fc67-4790-a3a9-8b672dcfe7a0@app.fastmail.com","threadId":"62441","inReplyTo":"9fd66b8f-c457-451b-9862-6121128b2786@app.fastmail.com","subject":"Re: Git revert cannot be aborted if the repository directory has been copied","fromName":"Kristoffer Haugsbakk","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2024-11-03T15:07:46Z","receivedAt":"2024-11-03T15:08:10Z","isPatch":false,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"On Sun, Nov 3, 2024, at 16:04, Kristoffer Haugsbakk wrote:\n> On Sun, Nov 3, 2024, at 03:34, Junio C Hamano wrote:\n>> Marco Stephan <marc.stephan96@hotmail.de> writes:\n>>\n>>> If you copy a Git repository directory to another path while there is a revert in progress for the Git repository, \"git revert --abort\" does not work anymore for the copied repository. Instead, it will report an error of the following format:\n>>>       error: Entry '...' not uptodate. Cannot merge.\n>>>       fatal: Could not reset index file to revision '...'.\n>>\n>> I wonder if\n>>\n>>     $ git update-index --refresh\n>>\n>> is all it takes.\n>\n>\n> This is correct.  This successful test can be added to\n> t3501-revert-cherry-pick.sh:\n\n(Meaning one can add it there if one wants to see for themselves)\n\n-- \nKristoffer Haugsbakk\n\n\n"},{"id":"506496","messageId":"89796e97-e5e1-4668-8b81-692579547bbf@app.fastmail.com","threadId":"62441","inReplyTo":"AM0PR02MB4980D186BDC087336C760132E6502@AM0PR02MB4980.eurprd02.prod.outlook.com","subject":"Re: Git revert cannot be aborted if the repository directory has been copied","fromName":"Kristoffer Haugsbakk","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2024-11-03T15:13:10Z","receivedAt":"2024-11-03T15:13:31Z","isPatch":false,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"On Sun, Nov 3, 2024, at 02:25, Marco Stephan wrote:\n> This consistently produces the error \"error: Entry 'test.txt' not\n> uptodate. Cannot merge.\". I would expect step 14 to work regardless of\n> how the repository directory itself has been created. Running \"git\n> status\" or \"git update --really-refresh\" fixes the seemingly corrupt\n> data and the revert in progress can be aborted.\n\nOkay, I missed that `git update-index --really-refresh` previously.\n\nI’m not a technical expert but is there a use-case here?  Or did you\nfind this by accident while doing something else?\n\n-- \nKristoffer Haugsbakk\n\n\n"},{"id":"506497","messageId":"VI1PR02MB4991FD152D121E6775195774E6502@VI1PR02MB4991.eurprd02.prod.outlook.com","threadId":"62441","inReplyTo":"89796e97-e5e1-4668-8b81-692579547bbf@app.fastmail.com","subject":"AW: Git revert cannot be aborted if the repository directory has been copied","fromName":"Marco Stephan","fromEmail":"marc.stephan96@hotmail.de","sentAt":"2024-11-03T17:33:17Z","receivedAt":"2024-11-03T17:33:26Z","isPatch":false,"sender":{"key":"marc.stephan96@hotmail.de","avatar":null},"body":"On Sun, Nov 3, 2024, at 16:13, Kristoffer Haugsbakk wrote:\n> Okay, I missed that `git update-index --really-refresh` previously.\n> \n> I’m not a technical expert but is there a use-case here?  Or did you\n> find this by accident while doing something else?\n\nI stumbled upon this behavior while working on some Git scripts. For these, I've prepared template repositories which I then copy and run the scripts on. This specific scenario in which I want to abort a revert in progress is, so far, the only scenario where this copying causes problems. All other Git commands I've used seem to simply ignore it or \"refresh the index\" on their own. For example, \"git cherry-pick --abort\" does not run into this problems for me."},{"id":"506507","messageId":"c1a8eb10-ac62-49f2-a40e-36c41bbdc991@gmail.com","threadId":"62441","inReplyTo":"AM0PR02MB4980D186BDC087336C760132E6502@AM0PR02MB4980.eurprd02.prod.outlook.com","subject":"Re: Git revert cannot be aborted if the repository directory has been copied","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2024-11-04T09:55:23Z","receivedAt":"2024-11-04T09:55:30Z","isPatch":false,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 03/11/2024 01:25, Marco Stephan wrote:\n> Hello,\n> \n> I have encountered the following bug:\n> If you copy a Git repository directory to another path while there is a revert in progress for the Git repository, \"git revert --abort\" does not work anymore for the copied repository. Instead, it will report an error of the following format:\n>       error: Entry '...' not uptodate. Cannot merge.\n>       fatal: Could not reset index file to revision '...'.\n\n\"git revert --abort\" is a wrapper around \"git reset --merge\" so I wonder \nif we should change \"git reset --merge\" to refresh the index.\n\nBest Wishes\n\nPhillip\n\n> I can reproduce the bug consistently with the latest version of Git that is available for Windows (git version 2.47.0.windows.2) by performing the following steps (all command line except step 12):\n> 1. mkdir test_repo\n> 2. cd test_repo\n> 3. git init\n> 4. type nul > test.txt\n> 5. git add .\n> 6. git commit -m \"Initial commit\"\n> 7. echo test > test.txt\n> 8. git add .\n> 9. git commit -m \"Changes\"\n> 10. git revert HEAD --no-commit\n> 11. cd ..\n> 12. Manually copy test_repo to a new directory test_repo_copy using the file explorer (using e.g. \"robocopy test_repo test_repo_copy /E\" does not corrupt the repository)\n> 13. cd test_repo_copy\n> 14. git revert --abort\n> This consistently produces the error \"error: Entry 'test.txt' not uptodate. Cannot merge.\". I would expect step 14 to work regardless of how the repository directory itself has been created. Running \"git status\" or \"git update --really-refresh\" fixes the seemingly corrupt data and the revert in progress can be aborted.\n> \n> I have not verified if the bug is present on other operation systems, too.\n> \n> With best regards\n> Marco Stephan\n\n"},{"id":"506810","messageId":"VI1PR02MB4991B262D45E1DE143494F13E65C2@VI1PR02MB4991.eurprd02.prod.outlook.com","threadId":"62441","inReplyTo":"c1a8eb10-ac62-49f2-a40e-36c41bbdc991@gmail.com","subject":"AW: Git revert cannot be aborted if the repository directory has been copied","fromName":"Marco Stephan","fromEmail":"marc.stephan96@hotmail.de","sentAt":"2024-11-07T19:52:54Z","receivedAt":"2024-11-07T19:52:57Z","isPatch":false,"sender":{"key":"marc.stephan96@hotmail.de","avatar":null},"body":"On Sun, Nov 4, 2024, at 10:55, Phillip Wood wrote:\n> \"git revert --abort\" is a wrapper around \"git reset --merge\" so I wonder\n> if we should change \"git reset --merge\" to refresh the index.\n\nIn my novice opinion I agree. If \"git revert --abort\" is just a wrapper for \"git reset --merge\" then I think \"git reset --merge\" should itself refresh the index. Other commands (e.g. \"git cherry-pick --abort\") seem to perform a refresh as well."}]}