On Thu, 21 Jun 2012 18:06:29 -0700 (PDT)
Git User <usv299792...@gmail.com> wrote:

> Thank you.
> Here is what I meant:
> echo alpha > a.txt
> add a.txt
> echo beta > b.txt
> add b.txt
> echo gamma >> b.txt
> Now I have a.txt and b.txt in staged state; and b.txt also has
> unstaged changes.
> I want to commit ONLY b.txt (i.e. I want to commit only 'beta' and
> leave b.txt in modified state with 'beta' & 'gamma' in it, 'gamma'
> being showed as '+gamma' in `git diff'.
> Something like `git commit --staged b.txt'
> In other words, how do we `git commit' just one file from the index
> if there are more than one files in the index.

I think you can't as you effectively wish to have one more level of
indirection (the second index).

I can imagine various workarounds to achieve what you want but they all
are imperfect in one way or another.

The proper way to do this probably would be to write your own porcelain
command that would:
1) Save a list of files with staged changes.
2) Reset all of the staged entries except for those files you specified.
   If any file to reset has unstaged local changes, refuse to proceed.
3) Commit.
4) Re-add the files that were reset on step (2).

You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To post to this group, send email to git-users@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to