git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* wishlist: "--cached|--staged" to "git commit file(s)"
@ 2018-08-13 16:22 Yaroslav Halchenko
  2018-08-13 21:33 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Yaroslav Halchenko @ 2018-08-13 16:22 UTC (permalink / raw)
  To: git@vger.kernel.org

Dear Git developers,

Following up on my quick question/discussion on IRC a few days
back:  Please consider adding --cached or --staged option for 

git commit file(s)

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.

Original usecase (I would be happy to elaborate):  committing specified
by user files in "direct" mode of git-annex, where it (via git annex
add) first converts files to the symlinks within index (they remain
original files within worktree), so we cannot use "git commit file(s)"
since then they would get committed disregarding their state in index.

But thinking about it I realized that it was quite a common use case to
me, that I typically stage all modified files whenever I reach "it is no
longer broken" stage, and then decide to commit that staged state in a
number of separate commits, and only then commit worktree state.

Current workaround as suggested on IRC is to 

- cp .git/index .git/index2
- GIT_INDEX_FILE=.git/index2 git reset files_not_to_be_committed
- GIT_INDEX_FILE=.git/index2 git commit
- rm .git/index2

or may be there is another (better) way?

-- 
Yaroslav O. Halchenko
Center for Open Neuroscience     http://centerforopenneuroscience.org
Dartmouth College, 419 Moore Hall, Hinman Box 6207, Hanover, NH 03755
Phone: +1 (603) 646-9834                       Fax: +1 (603) 646-1419
WWW:   http://www.linkedin.com/in/yarik        

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: wishlist: "--cached|--staged" to "git commit file(s)"
  2018-08-13 16:22 wishlist: "--cached|--staged" to "git commit file(s)" Yaroslav Halchenko
@ 2018-08-13 21:33 ` Junio C Hamano
  2018-08-14  0:37   ` Yaroslav Halchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2018-08-13 21:33 UTC (permalink / raw)
  To: Yaroslav Halchenko; +Cc: git@vger.kernel.org

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.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: wishlist: "--cached|--staged" to "git commit file(s)"
  2018-08-13 21:33 ` Junio C Hamano
@ 2018-08-14  0:37   ` Yaroslav Halchenko
  0 siblings, 0 replies; 3+ messages in thread
From: Yaroslav Halchenko @ 2018-08-14  0:37 UTC (permalink / raw)
  To: git@vger.kernel.org


On Mon, 13 Aug 2018, Junio C Hamano wrote:
> > 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"?

yes

> 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.

exactly

> Sounds like a good starter project for somebody who wants to try to
> get their hands dirty...

asking "around" ;-)


-- 
Yaroslav O. Halchenko
Center for Open Neuroscience     http://centerforopenneuroscience.org
Dartmouth College, 419 Moore Hall, Hinman Box 6207, Hanover, NH 03755
Phone: +1 (603) 646-9834                       Fax: +1 (603) 646-1419
WWW:   http://www.linkedin.com/in/yarik        

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-08-14  0:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-13 16:22 wishlist: "--cached|--staged" to "git commit file(s)" Yaroslav Halchenko
2018-08-13 21:33 ` Junio C Hamano
2018-08-14  0:37   ` Yaroslav Halchenko

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).