{"thread":{"id":"56418","subject":"BUG: `git commit` adding unstaged chunks of files to commits on 2.33.0","startedAt":"2021-08-31T17:15:31Z","lastAt":"2021-09-01T14:03:48Z","messageCount":7,"participants":["Andrew Thorp","Junio C Hamano","Philippe Blain"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"434306","messageId":"CAHBARKezrkKAs0ACbJ_fnxR-qWacQ5KKuVLwn0WyT7aR+4++pQ@mail.gmail.com","threadId":"56418","inReplyTo":null,"subject":"BUG: `git commit` adding unstaged chunks of files to commits on 2.33.0","fromName":"Andrew Thorp","fromEmail":"andrew.thorp.dev@gmail.com","sentAt":"2021-08-31T17:15:18Z","receivedAt":"2021-08-31T17:15:31Z","isPatch":false,"sender":{"key":"andrew.thorp.dev@gmail.com","avatar":"https://gravatar.com/avatar/a20a8710cb22582e3fada1e8b04c21a8bbac0d8106f45fc1c5c2fdbc57b3be1f?d=mp&s=160"},"body":"Hello all,\n\nAs described in the subject line, it seems like git commit is\ncommitting entire files when chunks of the files are staged using `git\nadd -p`, in spite of leaving chunks out of the stage. See below for\nthe bug-report template questionnaire. Please let me know if there is\nanything I can do to help resolve this issue or if there is anything\nneeded.\n\nThanks,\n\nAndrew Thorp\n\n\n> What did you do before the bug happened? (Steps to reproduce your issue)\n\nEdit a checked-in file, adding multiple chunks of lines to the file.\nUsing `git add -p <file>`, stage one of the chunks, leave some chunks unstaged.\nAfter running `git status` the file should both in the section\n`Changes to be committed:` and `Changes not staged for commit`.\nCommit the changes.\n\n> What did you expect to happen? (Expected behavior)\n\nI expected all staged changes to be committed and unstaged changes to\nremain unstaged.\n\n> What happened instead? (Actual behavior)\n\nThe entire file was committed, including the unstaged chunks of changes.\n\n> What's different between what you expected and what actually happened?\n\nIt appears as though the remaining file lines were both checked in and\ncommitted, when only the later should have happened.\n\n[System Info]\ngit version:\ngit version 2.33.0\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nuname: Darwin 20.4.0 Darwin Kernel Version 20.4.0: Thu Apr 22 21:46:47\nPDT 2021; root:xnu-7195.101.2~1/RELEASE_X86_64 x86_64\ncompiler info: clang: 12.0.5 (clang-1205.0.22.9)\nlibc info: no libc information available\n$SHELL (typically, interactive shell): /bin/zsh\n"},{"id":"434312","messageId":"xmqq4kb5v6p1.fsf@gitster.g","threadId":"56418","inReplyTo":"CAHBARKezrkKAs0ACbJ_fnxR-qWacQ5KKuVLwn0WyT7aR+4++pQ@mail.gmail.com","subject":"Re: BUG: `git commit` adding unstaged chunks of files to commits on 2.33.0","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-08-31T17:56:42Z","receivedAt":"2021-08-31T17:56:51Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andrew Thorp <andrew.thorp.dev@gmail.com> writes:\n\n>> What did you do before the bug happened? (Steps to reproduce your issue)\n>\n> Edit a checked-in file, adding multiple chunks of lines to the file.\n> Using `git add -p <file>`, stage one of the chunks, leave some chunks unstaged.\n> After running `git status` the file should both in the section\n> `Changes to be committed:` and `Changes not staged for commit`.\n> Commit the changes.\n\nHow was the last \"commit the changes\" done exactly?  \n\nIf either \"git commit -a\" or \"git commit <file>\" was done, that\nwould explain the symptom of having the entire up-to-date contents\nof <file> in the working tree recorded in the resulting commit.  The\nformer tells \"take all changes in the working tree\", the latter\ntells \"take the version of <file> in the working tree as a whole\",\nto Git to create a commit out of.\n\n\"git commit\" without pathspec would have made a partial commit that\nrecords only the changes that were added with \"git add -p\" to the\nindex, though.\n"},{"id":"434313","messageId":"CAHBARKfLC0ie4p=xWk+xDbEH72fSF6qeWCf=9oOTH6M9V1Qh=A@mail.gmail.com","threadId":"56418","inReplyTo":"xmqq4kb5v6p1.fsf@gitster.g","subject":"Re: BUG: `git commit` adding unstaged chunks of files to commits on 2.33.0","fromName":"Andrew Thorp","fromEmail":"andrew.thorp.dev@gmail.com","sentAt":"2021-08-31T18:01:14Z","receivedAt":"2021-08-31T18:01:27Z","isPatch":false,"sender":{"key":"andrew.thorp.dev@gmail.com","avatar":"https://gravatar.com/avatar/a20a8710cb22582e3fada1e8b04c21a8bbac0d8106f45fc1c5c2fdbc57b3be1f?d=mp&s=160"},"body":"> How was the last \"commit the changes\" done exactly?\n\nSo far I have confirmed this error occurs when running `git commit -m \"foo\"`,\n`git commit`, and `git commit --amend`.\n"},{"id":"434314","messageId":"CAHBARKcKL8h-zHcyCHRAMCj8=-PghopTPkH9o-_8UYRJYNZFmQ@mail.gmail.com","threadId":"56418","inReplyTo":"CAHBARKfLC0ie4p=xWk+xDbEH72fSF6qeWCf=9oOTH6M9V1Qh=A@mail.gmail.com","subject":"Re: BUG: `git commit` adding unstaged chunks of files to commits on 2.33.0","fromName":"Andrew Thorp","fromEmail":"andrew.thorp.dev@gmail.com","sentAt":"2021-08-31T18:01:57Z","receivedAt":"2021-08-31T18:02:14Z","isPatch":false,"sender":{"key":"andrew.thorp.dev@gmail.com","avatar":"https://gravatar.com/avatar/a20a8710cb22582e3fada1e8b04c21a8bbac0d8106f45fc1c5c2fdbc57b3be1f?d=mp&s=160"},"body":"> git commit\" without pathspec would have made a partial commit that\nrecords only the changes that were added with \"git add -p\" to the\nindex, though.\n\nYeah, that was the expected behavior, but not what I experienced.\n"},{"id":"434323","messageId":"xmqqczptto00.fsf@gitster.g","threadId":"56418","inReplyTo":"CAHBARKcKL8h-zHcyCHRAMCj8=-PghopTPkH9o-_8UYRJYNZFmQ@mail.gmail.com","subject":"Re: BUG: `git commit` adding unstaged chunks of files to commits on 2.33.0","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-08-31T19:25:51Z","receivedAt":"2021-08-31T19:25:57Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andrew Thorp <andrew.thorp.dev@gmail.com> writes:\n\n>> git commit\" without pathspec would have made a partial commit that\n> records only the changes that were added with \"git add -p\" to the\n> index, though.\n>\n> Yeah, that was the expected behavior, but not what I experienced.\n\nSorry but it does not reproduce for me.\n\nHere is my \"reproduction recipe\", designed to be followable by\nanybody who has a copy of git and this piece of e-mail without\nreferencing anything else.\n\n$ edit Makefile ; git diff Makefile\ndiff --git i/Makefile w/Makefile\nindex 9573190f1d..6bf8f3147b 100644\n--- i/Makefile\n+++ w/Makefile\n@@ -1,4 +1,4 @@\n-# The default target of this Makefile is...\n+# The default target of this Makefile is.....\n all::\n \n # Define V=1 to have a more verbose compile.\n@@ -30,7 +30,7 @@ all::\n # Define USE_LIBPCRE if you have and want to use libpcre. Various\n # commands such as log and grep offer runtime options to use\n # Perl-compatible regular expressions instead of standard or extended\n-# POSIX regular expressions.\n+# POSIX regular expressions...\n #\n # Only libpcre version 2 is supported. USE_LIBPCRE2 is a synonym for\n # USE_LIBPCRE, support for the old USE_LIBPCRE1 has been removed.\n\n... You can see that we have two changes to a single file now ...\n\n$ printf \"y\\nn\\n\" | git add -p >/dev/null\n$ git status -uno\nOn branch test\nChanges to be committed:\n  (use \"git restore --staged <file>...\" to unstage)\n\tmodified:   Makefile\n\nChanges not staged for commit:\n  (use \"git add <file>...\" to update what will be committed)\n  (use \"git restore <file>...\" to discard changes in working directory)\n\tmodified:   Makefile\n\nUntracked files not listed (use -u option to show untracked files)\n\n... And tell \"add -p\" to add the first but not the second hunk.\n\n$ git commit -m test\n\n... And commit.\n\n$ git status -uno\nOn branch test\nChanges not staged for commit:\n  (use \"git add <file>...\" to update what will be committed)\n  (use \"git restore <file>...\" to discard changes in working directory)\n\tmodified:   Makefile\n\nno changes added to commit (use \"git add\" and/or \"git commit -a\")\n\n... Then the working tree file stays dirty because the second hunk\nwas not added.\n\n$ git diff\ndiff --git i/Makefile w/Makefile\nindex fe6d649c27..6bf8f3147b 100644\n--- i/Makefile\n+++ w/Makefile\n@@ -30,7 +30,7 @@ all::\n # Define USE_LIBPCRE if you have and want to use libpcre. Various\n # commands such as log and grep offer runtime options to use\n # Perl-compatible regular expressions instead of standard or extended\n-# POSIX regular expressions.\n+# POSIX regular expressions...\n #\n # Only libpcre version 2 is supported. USE_LIBPCRE2 is a synonym for\n # USE_LIBPCRE, support for the old USE_LIBPCRE1 has been removed.\n\n... just as we can see here.  Of course, the first hunk is in the\ncommit, as can be seen ehre\n\n$ git diff HEAD^ HEAD\ndiff --git a/Makefile b/Makefile\nindex 9573190f1d..fe6d649c27 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1,4 +1,4 @@\n-# The default target of this Makefile is...\n+# The default target of this Makefile is.....\n all::\n \n # Define V=1 to have a more verbose compile.\n"},{"id":"434326","messageId":"CAHBARKcDBVbJ5fROe+CCrN5pDS057qJb91PMdN+28DUbPOSp0Q@mail.gmail.com","threadId":"56418","inReplyTo":"xmqqczptto00.fsf@gitster.g","subject":"Re: BUG: `git commit` adding unstaged chunks of files to commits on 2.33.0","fromName":"Andrew Thorp","fromEmail":"andrew.thorp.dev@gmail.com","sentAt":"2021-08-31T19:45:19Z","receivedAt":"2021-08-31T19:45:32Z","isPatch":false,"sender":{"key":"andrew.thorp.dev@gmail.com","avatar":"https://gravatar.com/avatar/a20a8710cb22582e3fada1e8b04c21a8bbac0d8106f45fc1c5c2fdbc57b3be1f?d=mp&s=160"},"body":"Ah, you're right. I have a pre-commit hook which does some formatting and\nthen re-adds the files. Doing so adds the unstaged chunks silently.\n\nThanks for taking a look Junio. I'll try to reproduce on a clean repo next time.\n\nCheers,\n\nAndrew Thorp\n"},{"id":"434449","messageId":"b1c3a0ce-dc27-9e3d-f1c5-7fe1e0ae2e53@gmail.com","threadId":"56418","inReplyTo":"CAHBARKezrkKAs0ACbJ_fnxR-qWacQ5KKuVLwn0WyT7aR+4++pQ@mail.gmail.com","subject":"Re: BUG: `git commit` adding unstaged chunks of files to commits on 2.33.0","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2021-09-01T14:03:49Z","receivedAt":"2021-09-01T14:03:48Z","isPatch":false,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Hi Andrew,\n\nLe 2021-08-31 à 13:15, Andrew Thorp a écrit :\n> Hello all,\n> \n>\n> \n> [System Info]\n> git version:\n> git version 2.33.0\n> cpu: x86_64\n> no commit associated with this build\n> sizeof-long: 8\n> sizeof-size_t: 8\n> shell-path: /bin/sh\n> uname: Darwin 20.4.0 Darwin Kernel Version 20.4.0: Thu Apr 22 21:46:47\n> PDT 2021; root:xnu-7195.101.2~1/RELEASE_X86_64 x86_64\n> compiler info: clang: 12.0.5 (clang-1205.0.22.9)\n> libc info: no libc information available\n> $SHELL (typically, interactive shell): /bin/zsh\n> \n\nAs I read downthread, the behaviour was due to your pre-commit hook.\n\nNormally below the \"System Info\" section in the 'git bugreport' template\nthere should be an \"Enabled Hooks\" section, which does not appear above.\nI would be curious to know why; I'm guessing you ran 'git bugreport' from\noutside your repo and so it said:\n\n[Enabled Hooks]\nnot run from a git repository - no hooks to show\n\nand you deleted that section ?\n\nI'm thinking that maybe if the 'git bugreport' template mentioned upfront that the\ncommand should be run in the repo where you observed a bug, maybe it would lead to\nfewer back and forth like in this thread ? (CC'ing Emily who implemented 'git bugreport').\n\nI've sent a PR [1] for the web site so that this is also mentioned at https://git-scm.com/community.\n\nCheers,\nPhilippe.\n\n[1] https://github.com/git/git-scm.com/pull/1629\n"}]}