{"thread":{"id":"49117","subject":"wishlist: \"--cached|--staged\" to \"git commit file(s)\"","startedAt":"2018-08-13T16:40:55Z","lastAt":"2018-08-14T00:37:20Z","messageCount":3,"participants":["Yaroslav Halchenko","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"355397","messageId":"20180813162236.GO732@hopa.kiewit.dartmouth.edu","threadId":"49117","inReplyTo":null,"subject":"wishlist: \"--cached|--staged\" to \"git commit file(s)\"","fromName":"Yaroslav Halchenko","fromEmail":"yoh@onerussian.com","sentAt":"2018-08-13T16:22:36Z","receivedAt":"2018-08-13T16:40:55Z","isPatch":false,"sender":{"key":"yoh@onerussian.com","avatar":"https://gravatar.com/avatar/8901b82415ae451a83aea49409708912726e53620e3ac92320bf1f86548d97e9?d=mp&s=160"},"body":"Dear Git developers,\n\nFollowing up on my quick question/discussion on IRC a few days\nback:  Please consider adding --cached or --staged option for \n\ngit commit file(s)\n\ncommand.  ATM there is no non-interactive (via --patch/--interactive I\nthink it is possible) way to commit selected subset of staged files not\nfrom the worktree (as it is done with \"git commit file(s)\") but from the\nindex.\n\nOriginal usecase (I would be happy to elaborate):  committing specified\nby user files in \"direct\" mode of git-annex, where it (via git annex\nadd) first converts files to the symlinks within index (they remain\noriginal files within worktree), so we cannot use \"git commit file(s)\"\nsince then they would get committed disregarding their state in index.\n\nBut thinking about it I realized that it was quite a common use case to\nme, that I typically stage all modified files whenever I reach \"it is no\nlonger broken\" stage, and then decide to commit that staged state in a\nnumber of separate commits, and only then commit worktree state.\n\nCurrent workaround as suggested on IRC is to \n\n- cp .git/index .git/index2\n- GIT_INDEX_FILE=.git/index2 git reset files_not_to_be_committed\n- GIT_INDEX_FILE=.git/index2 git commit\n- rm .git/index2\n\nor may be there is another (better) way?\n\n-- \nYaroslav O. Halchenko\nCenter for Open Neuroscience     http://centerforopenneuroscience.org\nDartmouth College, 419 Moore Hall, Hinman Box 6207, Hanover, NH 03755\nPhone: +1 (603) 646-9834                       Fax: +1 (603) 646-1419\nWWW:   http://www.linkedin.com/in/yarik        \n"},{"id":"355489","messageId":"xmqqva8e2bpf.fsf@gitster-ct.c.googlers.com","threadId":"49117","inReplyTo":"20180813162236.GO732@hopa.kiewit.dartmouth.edu","subject":"Re: wishlist: \"--cached|--staged\" to \"git commit file(s)\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-08-13T21:33:48Z","receivedAt":"2018-08-13T21:33:52Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Yaroslav Halchenko <yoh@onerussian.com> writes:\n\n> command.  ATM there is no non-interactive (via --patch/--interactive I\n> think it is possible) way to commit selected subset of staged files not\n> from the worktree (as it is done with \"git commit file(s)\") but from the\n> index.\n\nHmph, so\n\n\tedit A B C\n\tgit add A B\n\tedit A B C\n\tgit commit --cached B\n\nwould create a commit that is different from the original HEAD by\nthe edit to file B you did in the first step, but not the edit to A\nor C, or edit to B after you did \"git add\"?\n\nThat sounds like a useful feature.  If you do not need that \"exclude\nthe later edit since the last 'git add'\", you can do \"git commit B\",\nbut if you added crufts to B in the working tree since you added a\ngood copy of B to the index, that would not do what you want to do.\n\nSounds like a good starter project for somebody who wants to try to\nget their hands dirty.  I think it is just the matter of updating\nbuiltin/commit.c::prepare_index() where COMMIT_PARTIAL is handled,\nskipping \"(2) update the index with the given paths\" when \"--cached\"\noption is given, but doing everything else in that codepath.\n\n\n"},{"id":"355507","messageId":"20180814003712.GK580@hopa.kiewit.dartmouth.edu","threadId":"49117","inReplyTo":"xmqqva8e2bpf.fsf@gitster-ct.c.googlers.com","subject":"Re: wishlist: \"--cached|--staged\" to \"git commit file(s)\"","fromName":"Yaroslav Halchenko","fromEmail":"yoh@onerussian.com","sentAt":"2018-08-14T00:37:12Z","receivedAt":"2018-08-14T00:37:20Z","isPatch":false,"sender":{"key":"yoh@onerussian.com","avatar":"https://gravatar.com/avatar/8901b82415ae451a83aea49409708912726e53620e3ac92320bf1f86548d97e9?d=mp&s=160"},"body":"\nOn Mon, 13 Aug 2018, Junio C Hamano wrote:\n> > command.  ATM there is no non-interactive (via --patch/--interactive I\n> > think it is possible) way to commit selected subset of staged files not\n> > from the worktree (as it is done with \"git commit file(s)\") but from the\n> > index.\n\n> Hmph, so\n\n> \tedit A B C\n> \tgit add A B\n> \tedit A B C\n> \tgit commit --cached B\n\n> would create a commit that is different from the original HEAD by\n> the edit to file B you did in the first step, but not the edit to A\n> or C, or edit to B after you did \"git add\"?\n\nyes\n\n> That sounds like a useful feature.  If you do not need that \"exclude\n> the later edit since the last 'git add'\", you can do \"git commit B\",\n> but if you added crufts to B in the working tree since you added a\n> good copy of B to the index, that would not do what you want to do.\n\nexactly\n\n> Sounds like a good starter project for somebody who wants to try to\n> get their hands dirty...\n\nasking \"around\" ;-)\n\n\n-- \nYaroslav O. Halchenko\nCenter for Open Neuroscience     http://centerforopenneuroscience.org\nDartmouth College, 419 Moore Hall, Hinman Box 6207, Hanover, NH 03755\nPhone: +1 (603) 646-9834                       Fax: +1 (603) 646-1419\nWWW:   http://www.linkedin.com/in/yarik        \n"}]}