From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Rast Subject: [PATCH v5.1 5/6] Implement 'git checkout --patch' Date: Sat, 15 Aug 2009 13:48:30 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Cc: , Jeff King , Sverre Rabbelier , Nanako Shiraishi , Nicolas Sebrecht , Pierre Habouzit To: Junio C Hamano X-From: git-owner@vger.kernel.org Sat Aug 15 13:49:08 2009 Return-path: Envelope-to: gcvg-git-2@gmane.org Received: from vger.kernel.org ([209.132.176.167]) by lo.gmane.org with esmtp (Exim 4.50) id 1McHkx-0003I8-CS for gcvg-git-2@gmane.org; Sat, 15 Aug 2009 13:49:08 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753927AbZHOLsz (ORCPT ); Sat, 15 Aug 2009 07:48:55 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753920AbZHOLsz (ORCPT ); Sat, 15 Aug 2009 07:48:55 -0400 Received: from gwse.ethz.ch ([129.132.178.238]:54564 "EHLO gwse.ethz.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753787AbZHOLsy (ORCPT ); Sat, 15 Aug 2009 07:48:54 -0400 Received: from CAS01.d.ethz.ch (129.132.178.235) by gws01.d.ethz.ch (129.132.178.238) with Microsoft SMTP Server (TLS) id 8.1.375.2; Sat, 15 Aug 2009 13:48:53 +0200 Received: from localhost.localdomain (129.132.211.129) by mail.ethz.ch (129.132.178.227) with Microsoft SMTP Server (TLS) id 8.1.375.2; Sat, 15 Aug 2009 13:48:51 +0200 X-Mailer: git-send-email 1.6.4.287.g3e02d In-Reply-To: Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: This introduces a --patch mode for git-checkout. In the index usage git checkout --patch -- [files...] it lets the user discard edits from the at the granularity of hunks (by selecting hunks from 'git diff' and then reverse applying them to the worktree). We also accept a revision argument. In the case git checkout --patch HEAD -- [files...] we offer hunks from the difference between HEAD and the worktree, and reverse applies them to both index and worktree, allowing you to discard staged changes completely. In the non-HEAD usage git checkout --patch -- [files...] it offers hunks from the difference between the worktree and . The chosen hunks are then applied to both index and worktree. The application to worktree and index is done "atomically" in the sense that we first check if the patch applies to the index (it should always apply to the worktree). If it does not, we give the user a choice to either abort or apply to the worktree anyway. Signed-off-by: Thomas Rast --- I found another mismatch of the -R flags during double checking, as follows: diff --git c/git-add--interactive.perl i/git-add--interactive.perl index 2363a77..21746d5 100755 --- c/git-add--interactive.perl +++ i/git-add--interactive.perl @@ -117,7 +117,7 @@ 'checkout_head' => { DIFF => 'diff-index -p', APPLY => sub { apply_patch_for_checkout_commit '-R', @_ }, - APPLY_CHECK => 'apply', + APPLY_CHECK => 'apply -R', VERB => 'Discard', TARGET => ' from index and worktree', PARTICIPLE => 'discarding', Documentation/git-checkout.txt | 13 +++++- builtin-checkout.c | 19 +++++++ git-add--interactive.perl | 61 +++++++++++++++++++++++ t/t2015-checkout-patch.sh | 107 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 199 insertions(+), 1 deletions(-) create mode 100755 t/t2015-checkout-patch.sh diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt index ad4b31e..26a5447 100644 --- a/Documentation/git-checkout.txt +++ b/Documentation/git-checkout.txt @@ -11,6 +11,7 @@ SYNOPSIS 'git checkout' [-q] [-f] [-m] [] 'git checkout' [-q] [-f] [-m] [-b ] [] 'git checkout' [-f|--ours|--theirs|-m|--conflict=