git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: wishlist: "--cached|--staged" to "git commit file(s)"

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 13, 2018, 21:33 UTC
Message-ID
<xmqqva8e2bpf.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20180813162236.GO732@hopa.kiewit.dartmouth.edu>
Yaroslav Halchenko <yoh@onerussian.com> writes:
> command.  ATM there is no non-interactive (via --patch/--interactive I
> think it is possible) way to commit selected subset of staged files not
> from the worktree (as it is done with "git commit file(s)") but from the
> index.
Hmph, so
	edit A B C
	git add A B
	edit A B C
	git commit --cached B

would create a commit that is different from the original HEAD by the edit to file B you did in the first step, but not the edit to A or C, or edit to B after you did "git add"?

That sounds like a useful feature. If you do not need that "exclude the later edit since the last 'git add'", you can do "git commit B", but if you added crufts to B in the working tree since you added a good copy of B to the index, that would not do what you want to do.

Sounds like a good starter project for somebody who wants to try to get their hands dirty. I think it is just the matter of updating builtin/commit.c::prepare_index() where COMMIT_PARTIAL is handled, skipping "(2) update the index with the given paths" when "--cached" option is given, but doing everything else in that codepath.

Previous: Yaroslav HalchenkoNext: Yaroslav Halchenko
Message 2 of 3 in “wishlist: "--cached|--staged" to "git commit file(s)"”
  1. Yaroslav HalchenkoAug 13, 2018
  2. Junio C HamanoAug 13, 2018
  3. Yaroslav HalchenkoAug 14, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.