All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anders Kaseorg <andersk@mit.edu>
To: "git@vger.kernel.org" <git@vger.kernel.org>
Cc: Elijah Newren <newren@gmail.com>
Subject: v2.25 regression: cherry-pick alters patch and leaves working tree dirty
Date: Sat, 12 Jun 2021 07:34:46 +0000	[thread overview]
Message-ID: <148044c89c194a82aa15ab0ca016669d@oc11expo7.exchange.mit.edu> (raw)

I ran into a problem where git cherry-pick incorrectly alters a patch that should apply cleanly, and leaves the working tree dirty despite claiming to finish successfully. I minimized the problem to the reproduction recipe below. Bisecting git.git shows the problem was introduced by 49b8133a9ece199a17db8bb2545202c6eac67485 (v2.25.0-rc0~144^2~1) “merge-recursive: fix merging a subdirectory into the root directory”, and it remains a problem in v2.32.0.

To reproduce:

git init
echo foo >foo
echo bar >bar
echo baz >baz
git add foo bar baz
git commit -m 'Initial commit'
mkdir dir
git mv foo dir/foo
git commit -am 'Move foo'
git mv bar dir/bar
echo baz >>baz
git commit -am 'Move bar'
git tag move-bar
git reset --hard move-bar~2
git cherry-pick move-bar

The rename part of the patch has been unexpectedly lost, and ‘bar’ has been unexpectedly deleted from the working tree:

$ git show
commit f06592b45db70540983a6c3e8bcf62712c694257
Author: Anders Kaseorg <andersk@mit.edu>
Date:   Sat Jun 12 00:20:13 2021 -0700

    Move bar

diff --git a/baz b/baz
index 7601807..1f55335 100644
--- a/baz
+++ b/baz
@@ -1 +1,2 @@
 baz
+baz

$ git status
On branch master
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	deleted:    bar

no changes added to commit (use "git add" and/or "git commit -a")

Before 49b8133a9e, the results are as expected:

$ git show
commit b7a2a3505dae3589203ca4469cb49e8a8e2727c3
Author: Anders Kaseorg <andersk@mit.edu>
Date:   Sat Jun 12 00:23:07 2021 -0700

    Move bar

diff --git a/baz b/baz
index 7601807..1f55335 100644
--- a/baz
+++ b/baz
@@ -1 +1,2 @@
 baz
+baz
diff --git a/bar b/dir/bar
similarity index 100%
rename from bar
rename to dir/bar

$ git status
On branch master
nothing to commit, working tree clean

Anders

             reply	other threads:[~2021-06-12  7:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-12  7:34 Anders Kaseorg [this message]
2021-06-13  6:57 ` Elijah Newren
2021-06-13  7:45   ` Anders Kaseorg
2021-06-26 17:14     ` Elijah Newren

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=148044c89c194a82aa15ab0ca016669d@oc11expo7.exchange.mit.edu \
    --to=andersk@mit.edu \
    --cc=git@vger.kernel.org \
    --cc=newren@gmail.com \
    --subject='Re: v2.25 regression: cherry-pick alters patch and leaves working tree dirty' \
    /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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.