From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B0A1364EA5 for ; Tue, 28 Apr 2026 09:35:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777368936; cv=none; b=pMmX6557Kq4grRmrqswLkvEHKdDyVkXqOaoC85qSzrNRz+TjD6bKz7HoxNPrEHrIljfzCiWHj57rOWYHzbnSqh70LTiW/I6zvcGRyEnwNCaGE5qgkD9OCUdRER2T14iRM3AINRHA++r6nYiFHdWmakJj/ZkI75vSmuHx6VPPiMs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777368936; c=relaxed/simple; bh=9gRFsE+3nMrA+Mr8NgsV0bzHpiMfl/fYHkWdj0Lvy8g=; h=Message-ID:Date:MIME-Version:From:Subject:To:Cc:References: In-Reply-To:Content-Type; b=EVz/HQdy/7ZljXRPOOkt5oSwQn694yce9CE28FwpXBOj/XLIGVXrA33S3xOHb/isY0idNqFdkQopgSiiamEJWAtSRh6yjJS0kisacNe6rPwTT7So6/X75O7jEDsDPGxaA2dN1YF5znjpH0etUdLxjLYrKMIlkiHhoaYscOnRC5Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=qvRhR7BH; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qvRhR7BH" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-488e1a8ac40so138018165e9.2 for ; Tue, 28 Apr 2026 02:35:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777368932; x=1777973732; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:reply-to:from:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=xtl27V6qrFwdBImevipYKlfezE7OjFfT0jAlUE/dIR0=; b=qvRhR7BHXbqqpfLZYQk/dXa5iOml0xVY55LbIeUggSv2hFoqc/6SC42uuQzsHP1JLq BX2oBHGsUbPI8O5RObvjvvHww7VqaZCZyjg2C/pufGrp0k5PbZc7C8L/cd0W94pPwOef ZHrGUrThTOUNY9hH7C8Fk7FCiSL//V61Whl/SKmlG6sF3mStMj1pOhKL05/A9qvxEhUy 2DGxIwA2CEcSqdYtjvfAEt9yiOc+cr5U69OlObdGw7w8nRQXmDvNE8Cu6niOiaBxqH5Z mdkfeM1vGpiVAXSLctHzNQNLT/KcykVsPmiCRUlBGcQCsp8vVNOP5aOzESnZMq76WHzd 1/wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777368932; x=1777973732; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:reply-to:from:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xtl27V6qrFwdBImevipYKlfezE7OjFfT0jAlUE/dIR0=; b=Tt4a0mS9PfZapQSu3ZDxixlDrKMWvSHEzuYjv+sWl2+rvhZhoOASUbLDSfggq7+7L7 SCSE+hj2GpErGXR6y/Svv7ypW05YArnBV+8FqN6kFfBwp1WPW2e26qVlI/TUcPF0b4tH 3OwbOGHg2triJR2ii+jNMH71Ylw9GgnMwW7arsTPn6VAiOmv+JNn2yUg+RSS/ihI0PQr Nnnjicp3cpkMcuYFawV8C61rdLUEROsiuho36lM6v7AEhfImqDYcDwTPVI18CIkh0bwV 6IfjHIM9U7TZtBVoNKeFL9N8prkQCp3ib9Cqym6M8a+udZN7HfMqsiDSkL2fz1rxawOy HS3w== X-Forwarded-Encrypted: i=1; AFNElJ9JnMCNH9u3LKMctfnmyVqiWlvfLY/GSHNuJx1pn7bOcLg8KQpwM7ZMXV1AQQaN98dPxqc=@vger.kernel.org X-Gm-Message-State: AOJu0YzlFObcNKl27r+Jmsi8RjIsF86HLkSoK0VzPBH3cY51b/5+Ns4x iKg8FS/Tw+rrUlvlPFYCVRp5lBXmTb9lmaooE8Kn2m0VH05+aTgJz0KKf9qaSw== X-Gm-Gg: AeBDieu0LT3TDHgzTqyclxMp2zbDNyuub35yPKSPkoRHvge9gpZqs3bQI8HP8BJESc9 RBhB6VykbT46D2pyIcGpQl2QPEgPsk3JhsELalSUo1v9oXapUFTm7fNnaYdlgmGp6YAQB+B3vzH YH09Ct/AjITVom7rVf9m2lndKO7VQ+RrEK7FVnHSAJlcS2uTKwGgSuBByxssaBQa4YaMhyC7XzD fl7/3T9XV+In9e1PZrf7lEjUcS4uRqgXMOfF+QLk7FppTNawZpv6H3N22n1nCU3q+S9yx017aFA mgUicMEB1bqcI5+dnJIt3kSoA1ISrXXxX8RaLivojktJj6UjrNPYx33qnOlg/esByiU55yQeIFR SmwmR6I1EFoO95Bgn/fYHGdlyq10fh/AHwK27feOS4w95x4i7+hW460Vmy6Ss6nK1rhLRo3lIUe okVL6VsGXKHusUknH3VsIRuHfkNr/PbNSlT6+gX0RgzoDEMvN4iQpsyJJM9q2zLz/j6gnLIgMKy sex8fghdLSDjoKF5ynalV3N X-Received: by 2002:a05:600c:820c:b0:488:c683:be89 with SMTP id 5b1f17b1804b1-48a77adc749mr39388945e9.9.1777368932177; Tue, 28 Apr 2026 02:35:32 -0700 (PDT) Received: from ?IPV6:2a0a:ef40:7d8:fa01:60c8:18fb:2acc:d4f? ([2a0a:ef40:7d8:fa01:60c8:18fb:2acc:d4f]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a773af544sm45864805e9.6.2026.04.28.02.35.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 28 Apr 2026 02:35:31 -0700 (PDT) Message-ID: <88a89e06-5223-4a6f-8f9e-66e72b632ee2@gmail.com> Date: Tue, 28 Apr 2026 10:35:29 +0100 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Phillip Wood Reply-To: phillip.wood@dunelm.org.uk Subject: Re: [PATCH v15 5/5] checkout -m: autostash when switching branches To: Harald Nordgren via GitGitGadget , git@vger.kernel.org Cc: Chris Torek , Jeff King , Harald Nordgren References: <96b14db827e51966aceb6513f7d16ed526274ec2.1777065012.git.gitgitgadget@gmail.com> Content-Language: en-US In-Reply-To: <96b14db827e51966aceb6513f7d16ed526274ec2.1777065012.git.gitgitgadget@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi Harald On 24/04/2026 22:10, Harald Nordgren via GitGitGadget wrote: > From: Harald Nordgren > > When switching branches with "git checkout -m", the attempted merge > of local modifications may cause conflicts with the changes made on > the other branch, which the user may not want to (or may not be able > to) resolve right now. Because there is no easy way to recover from > this situation, we discouraged users from using "checkout -m" unless > they are certain their changes are trivial and within their ability > to resolve conflicts. > > Teach the -m flow to create a temporary stash before switching and > reapply it after. On success, the stash is silently applied and > the list of locally modified paths is shown, same as a successful > "git checkout" without "-m". > > If reapplying causes conflicts, the stash is kept and the user is > told they can resolve and run "git stash drop", or run "git reset > --hard" and later "git stash pop" to recover their changes. This is looking good, there are just a few small issues. Hopefully the next iteration will be the last. > Signed-off-by: Harald Nordgren > --- > Documentation/git-checkout.adoc | 58 ++++++------ > Documentation/git-switch.adoc | 33 +++---- > builtin/checkout.c | 160 ++++++++++++++------------------ > sequencer.c | 14 ++- > t/t3420-rebase-autostash.sh | 16 ++-- > t/t7201-co.sh | 61 +++++++++++- > t/t7600-merge.sh | 3 +- > xdiff-interface.c | 12 +++ > xdiff-interface.h | 1 + > 9 files changed, 211 insertions(+), 147 deletions(-) > > diff --git a/Documentation/git-checkout.adoc b/Documentation/git-checkout.adoc > index 43ccf47cf6..70dd211ee3 100644 > --- a/Documentation/git-checkout.adoc > +++ b/Documentation/git-checkout.adoc > @@ -251,20 +251,19 @@ working tree, by copying them from elsewhere, extracting a tarball, etc. > are different between the current branch and the branch to > which you are switching, the command refuses to switch > branches in order to preserve your modifications in context. > - However, with this option, a three-way merge between the current > - branch, your working tree contents, and the new branch > - is done, and you will be on the new branch. > -+ > -When a merge conflict happens, the index entries for conflicting > -paths are left unmerged, and you need to resolve the conflicts > -and mark the resolved paths with `git add` (or `git rm` if the merge > -should result in deletion of the path). > + With this option, the conflicting local changes are > + automatically stashed before the switch and reapplied > + afterwards. If the local changes do not overlap with the > + differences between branches, the switch proceeds without > + stashing. If reapplying the stash results in conflicts, the > + entry is saved to the stash list. Resolve the conflicts > + and run `git stash drop` when done, or clear the working > + tree (e.g. with `git reset --hard`) before running `git stash > + pop` later to re-apply your changes. > + > When checking out paths from the index, this option lets you recreate > the conflicted merge in the specified paths. This option cannot be > used when checking out paths from a tree-ish. > -+ > -When switching branches with `--merge`, staged changes may be lost. > > `--conflict=