From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>, git@vger.kernel.org
Subject: Re: [PATCH] update-index: add --swap to swap index and worktree content
Date: Tue, 16 Aug 2011 14:01:08 -0700 [thread overview]
Message-ID: <20110816210108.GA13710@sigill.intra.peff.net> (raw)
In-Reply-To: <7vippxgm6y.fsf@alter.siamese.dyndns.org>
On Tue, Aug 16, 2011 at 01:01:41PM -0700, Junio C Hamano wrote:
> Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
>
> > What I want is a quick way to modify index content without changing
> > worktree, then I can continue adding more hunks to the index.
>
> Why would you even want to do that?
>
> Suppose you want to update hello.c in the index but not in the working
> tree for whatever reason I do not understand. Presumably you would with
> this patch do this:
>
> edit hello.c
> git update-index --swap hello.c
>
> assuming that the state of hello.c _before_ the edit was pristine. But
> then after that what would you do? Probably you would commit that
> untested change, and rebase-i to clean them up later, which is fine.
I suspect (or at least, this is how I would use it) it is more about
having some changes in the index and some changes in the working tree,
but realizing that what's in the index needs tweaked. Something like:
# add some content with an error
echo 'printf("hello word!\n")' >hello.c
git add hello.c
# work on it more, realizing the error
echo 'printf("goodbye world!\n") >hello.c
# now what? you want to stage the s/word/world/ fixup,
# but you want to keep the hello/goodbye thing as a separate change.
# Using anything line-based is going to conflate the two.
# The change is simple, though, so you can just as easily edit the
# index file, if only you could get to it. So you do:
git update-index --swap hello.c
sed -i s/word/world/ hello.c
git update-index --swap hello.c
So the swap really functions as a toggle of "I would like to work on
the index version for a minute", and then you toggle back when you're
done.
I can think of two ways to do the same thing that are a little less
confusing or error-prone, though:
1. A command to dump the index version to a tempfile, run $EDITOR on
it, and then read it back in. Technically this restricts you to
using $EDITOR to make the changes, but in practice that is probably
fine.
2. You can dump the file to a pipe yourself, but getting it back into
the index is a little bit awkward. You have to do something like:
blob=`git cat-file blob :hello.c |
sed 's/word/world/ |
git hash-object --stdin -w`
mode=`git ls-files -s hello.c | cut -d' ' -f1`
git update-index --cacheinfo $mode $blob hello.c
it would be much nicer if this was:
git cat-file blob :hello.c |
sed 's/word/world/ |
git add --stdin-contents hello.c
However, I expect this sort of piping is the minority case, and
most people would be happy with (1).
-Peff
next prev parent reply other threads:[~2011-08-16 21:01 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-12 14:07 [PATCH] update-index: add --swap to swap index and worktree content Nguyễn Thái Ngọc Duy
2011-08-16 13:01 ` Michael J Gruber
2011-08-16 14:45 ` Nguyen Thai Ngoc Duy
2011-08-16 20:01 ` Junio C Hamano
2011-08-16 21:01 ` Jeff King [this message]
2011-08-16 21:56 ` Junio C Hamano
2011-08-16 22:22 ` Jeff King
2011-08-16 23:01 ` Junio C Hamano
2011-08-16 23:06 ` Jeff King
2011-08-17 2:11 ` Nguyen Thai Ngoc Duy
2011-08-17 2:17 ` Jeff King
2011-08-17 14:13 ` Martin von Zweigbergk
2011-08-17 14:32 ` Nguyen Thai Ngoc Duy
2011-08-17 18:26 ` Junio C Hamano
2011-08-17 19:46 ` Jeff King
2011-08-18 1:01 ` Martin von Zweigbergk
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=20110816210108.GA13710@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=pclouds@gmail.com \
/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).