git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Frans Klaver" <fransklaver@gmail.com>
To: git@vger.kernel.org, "Horst H. von Brand" <vonbrand@inf.utfsm.cl>
Subject: Re: git 1.8.0.rc0.18.gf84667d trouble with "git commit -p file"
Date: Fri, 05 Oct 2012 21:55:07 +0200	[thread overview]
Message-ID: <op.wlp1lws70aolir@keputer> (raw)
In-Reply-To: <201210051420.q95EKjj3008300@netbook1.inf.utfsm.cl>

On Fri, 05 Oct 2012 16:20:45 +0200, Horst H. von Brand  
<vonbrand@inf.utfsm.cl> wrote:

> What I did:
>
> - New file images/coins.asy ~~-> 'git add images/coins.asy'
> - Started adding new stuff to fg.tex
> - Noticed a old bug in fg.tex, fixed that one
> - Did 'git -pm "Some message"' and selected just the bugfix
>
> But git created a commit _including_ the new file. Tried to go back:

Exactly what's supposed to happen. "git add" tells git you want to add the  
file to the index. The index is what you're going to commit later on. So  
what you did there was

- Tell git to add images/coins.asy to the next commit
- hack hack hack
- fix old_bug
- Add old_bug chunks of code to next commit && create commit

>
> - 'git reset HEAD^'
>
> Now the new file isn't staged anymore
>
>
> What I expected to happen:
>
> - Only the explicitly selected chunks commited
> - No "losing staged changes"

As explained above, you didn't lose staged changes, you staged more  
changes and committed. Then you use git reset to go back to the state of  
HEAD^, where the file wasn't tracked and therefore not staged either.

So you're back at square one[1], commit the bug fix, then add the bugfixes  
in a commit and stage the new file for inclusion in your next commit.

Hope this helps,
Frans

[1] Arguably two, since you still have changes lying around.

  reply	other threads:[~2012-10-05 19:55 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-05 14:20 git 1.8.0.rc0.18.gf84667d trouble with "git commit -p file" Horst H. von Brand
2012-10-05 19:55 ` Frans Klaver [this message]
2012-10-05 22:29   ` Junio C Hamano
2012-10-05 22:57     ` Jeff King
2012-10-06  6:26       ` Junio C Hamano
2012-10-06 13:12         ` Jeff King
2012-10-06 18:22           ` Junio C Hamano
2012-10-06 18:30             ` Jeff King
2012-10-06 18:32               ` Conrad Irwin
2012-10-06 19:07                 ` Jeff King
2012-10-07 20:51                   ` Junio C Hamano
2012-10-07 21:49                     ` Jeff King
2012-10-07 22:23                       ` Junio C Hamano
2012-10-07 22:25                         ` Jeff King
2012-10-11  5:51                           ` Conrad Irwin
2012-10-11 17:57                             ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=op.wlp1lws70aolir@keputer \
    --to=fransklaver@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=vonbrand@inf.utfsm.cl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).