Re: git 1.8.0.rc0.18.gf84667d trouble with "git commit -p file"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 05 Oct 2012 16:20:45 +0200, Horst H. von Brand <vonbrand@xxxxxxxxxxxx> 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.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]