git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: Josh Triplett <josh@joshtriplett.org>
Cc: git@vger.kernel.org, Wincent Colaiuta <win@wincent.com>,
	Thomas Rast <trast@student.ethz.ch>, Jeff King <peff@peff.net>
Subject: Re: Please support add -p with a new file, to add only part of the file
Date: Mon, 9 Jan 2012 14:47:21 -0600	[thread overview]
Message-ID: <20120109204721.GC23825@burratino> (raw)
In-Reply-To: <20120109105134.1239.39047.reportbug@leaf>

(+cc: Wincent who brought us the "add -p" shortcut --- thanks!; Thomas,
 who expanded its scope to git checkout et al; and Jeff, who has done
 some hacking on it)
Hi Josh,

Josh Triplett wrote:

> I recently found myself with a new file that I needed to check in part
> of with several commits.  I wanted to use "git add -p newfile" and use
> 'e' to add and commit several times (along with corresponding bits in
> existing files).  However, "git add -p" does not work on a new file,
> only an existing file.

Yep.  A workaround is to use "git add -N newfile" before running
"git add -p newfile".

I imagine "git add -p '*.c'" should also offer to add hunks from
source files that git doesn't know about yet, too.

Here's a quick demo (untested) that might _almost_ do the right thing.
Unfortunately it leaves intent-to-add entries around even for files
the operator rejects.  Anyway, maybe it can be a good starting point
for playing around.

Hope that helps,
Jonathan

 git-add--interactive.perl |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 8f0839d2..6e99ff1b 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -1619,6 +1619,10 @@ sub main_loop {
 process_args();
 refresh();
 if ($patch_mode) {
+	if ($patch_mode eq 'stage') {
+		# NEEDSWORK: should use "git update-index --intent-to-add"
+		system(qw(git add --intent-to-add --), @ARGV);
+	}
 	patch_update_cmd();
 }
 else {
-- 
1.7.8.2

       reply	other threads:[~2012-01-09 20:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20120109105134.1239.39047.reportbug@leaf>
2012-01-09 20:47 ` Jonathan Nieder [this message]
2012-01-10 14:07   ` Please support add -p with a new file, to add only part of the file Thomas Rast
2012-01-10 18:32     ` Junio C Hamano
2012-01-10 18:38       ` Jeff King
2012-01-10 19:33         ` Junio C Hamano
2012-01-10 19:38           ` Jeff King
2012-01-10 22:29             ` Josh Triplett

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=20120109204721.GC23825@burratino \
    --to=jrnieder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=josh@joshtriplett.org \
    --cc=peff@peff.net \
    --cc=trast@student.ethz.ch \
    --cc=win@wincent.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).