{"thread":{"id":"63288","subject":"Bug: git difftool --tool=meld -d HEAD^ lose copied file","startedAt":"2025-04-13T14:07:32Z","lastAt":"2025-04-13T15:11:27Z","messageCount":2,"participants":["Kirill","K Jayatheerth"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"516057","messageId":"CAKFQ_Q93M=x_xNuCm_evjUSfi_cNGQ0LuZSHVua1vTZHc0e-7w@mail.gmail.com","threadId":"63288","inReplyTo":null,"subject":"Bug: git difftool --tool=meld -d HEAD^ lose copied file","fromName":"Kirill","fromEmail":"ks1322@gmail.com","sentAt":"2025-04-13T14:07:20Z","receivedAt":"2025-04-13T14:07:32Z","isPatch":false,"sender":{"key":"ks1322@gmail.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)\n\nmkdir git-copy-lost\ncd git-copy-lost\ngit init\ntouch file\ngit add file\ngit commit -am \"message\"\ngit rm file\ngit commit -am \"message\"\ngit difftool --tool=meld -d HEAD^\n\nIn meld right click on `file` in left pane and press \"Copy To Right\" in menu\nQuit meld\n\nls -l\n\nWhat did you expect to happen? (Expected behavior)\n\n`file` is present in working directory\n\nWhat happened instead? (Actual behavior)\n\n`file` is absent in working directory\n\nWhat's different between what you expected and what actually happened?\n\n`file` is missing while it was copied in meld with \"Copy To Right\" button\n\nAnything else you want to add:\n\nThis bug was also reported for meld but I don't think meld can do\nanything with it\nbecause copied file is being lost in temporary directory like\n/tmp/git-difftool.7bOf2n/right/ created by git\nMeld bug: https://gitlab.gnome.org/GNOME/meld/-/issues/555\n\nPlease review the rest of the bug report below.\nYou can delete any lines you don't wish to share.\n\n\n[System Info]\ngit version:\ngit version 2.49.0\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nlibcurl: 8.9.1\nOpenSSL: OpenSSL 3.2.4 11 Feb 2025\nzlib-ng: 2.2.3\nuname: Linux 6.13.9-200.fc41.x86_64 #1 SMP PREEMPT_DYNAMIC Sat Mar 29\n01:29:31 UTC 2025 x86_64\ncompiler info: gnuc: 14.2\nlibc info: glibc: 2.40\n$SHELL (typically, interactive shell): /bin/bash\n\n\n[Enabled Hooks]\n"},{"id":"516058","messageId":"20250413151111.76851-1-jayatheerthkulkarni2005@gmail.com","threadId":"63288","inReplyTo":"CAKFQ_Q93M=x_xNuCm_evjUSfi_cNGQ0LuZSHVua1vTZHc0e-7w@mail.gmail.com","subject":"Re: Bug: git difftool --tool=meld -d HEAD^ lose copied file","fromName":"K Jayatheerth","fromEmail":"jayatheerthkulkarni2005@gmail.com","sentAt":"2025-04-13T15:11:11Z","receivedAt":"2025-04-13T15:11:27Z","isPatch":false,"sender":{"key":"jayatheerthkulkarni2005@gmail.com","avatar":"https://avatars.githubusercontent.com/u/148841023?v=4"},"body":"From: Jayatheerth <jayatheerthkulkarni2005@gmail.com> // <-- FIXED\n\nOn 2025-04-13 14:07 UTC, Kirill wrote:\n> Hi Git developers,\n>\n\nHey, Kirill\nThanks for the detailed report.\n\n> I believe I've found unexpected behavior when using `git difftool -d`\n> with an external tool like Meld, where actions within the tool do not\n> affect the working directory as might be intuitively expected.\n>\n> [Steps to reproduce snipped]\n>\n> My understanding is that `git difftool -d` operates by checking out the\n> compared tree-ishes into temporary directories (e.g., `/tmp/git-difftool.XXXX/left`\n> representing `HEAD^` and `/tmp/git-difftool.XXXX/right` representing the\n> working directory state).\n>\n> Meld performs the copy operation successfully *between these temporary directories*.\n> The file exists in `/tmp/git-difftool.XXXX/right/file` before Meld exits.\n>\n> However, upon Meld's exit, Git cleans up by removing these temporary\n> directories entirely. The copied file within the temporary 'right' directory\n> is discarded, and the change is never propagated back to the actual\n> working directory.\n\nYes, your understanding of the temporary directory creation, the successful\ncopy *within* those directories by Meld, and the subsequent cleanup\nby Git discarding those changes is entirely correct. This is the\ndesigned mechanism.\n\n> While this might be the intended design (operating safely on temporary copies),\n> it leads to counter-intuitive behavior and data loss (of the action performed\n> in the difftool) for users expecting interactive modification capabilities\n> similar to, perhaps, `git mergetool`.\n>\n> This behavior was also reported against Meld, but it seems unlikely Meld\n> can address it, as the temporary directories and the cleanup process are\n> managed by Git:\n> Meld bug: https://gitlab.gnome.org/GNOME/meld/-/issues/555\n>\n\nHowever, you are absolutely right that this intended behavior is counter-intuitive for users interacting with graphical tools like Meld, where actions like \"Copy to Right\" or direct editing feel like they should have a persistent effect. It's a frequent point of confusion, as evidenced by the Meld issue you linked as well.\n\nWhile changing this core behavior of `difftool -d` would be a significant design shift with potential safety implications, perhaps the most practical improvement would be to enhance the documentation. The `git-difftool(1)` man page could more explicitly warn users that when using `--dir-diff`, modifications made within the external tool to the temporary directories are *not* propagated back to the working directory.\n\nFor achieving the outcome you expected (restoring the file from the previous commit), the standard Git way remains using commands designed for working directory manipulation, such as:\n\n`git restore --source=HEAD^ file`\n\nor the older:\n\n`git checkout HEAD^ -- file`\n\nThanks again for bringing this usability issue to the list's attention. Clearer documentation might help prevent future confusion.\n\n>\n> [System Info snipped]\n>\n> Thanks,\n> Kirill\n\n--\n-Jayatheerth\n"}]}