git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: cherry-pick applies some other changes than the specified one?

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 21, 2011, 16:09 UTC
Message-ID
<7vwrjssbfk.fsf@alter.siamese.dyndns.org>
In-Reply-To
<AANLkTikE5AqJyShN+GfFYe0kBS=ShGnKQcnwbarNZrjm@mail.gmail.com>
Piotr Krukowiecki <piotr.krukowiecki@gmail.com> writes:
Show 10 quoted lines
> There's a conflict during the cherry-pick. git status shows:
>
> $ git status
> # On branch 9_0
> # Unmerged paths:
> #   (use "git add/rm <file>..." as appropriate to mark resolution)
> #
> #	both modified:      etc/file
> #
> no changes added to commit (use "git add" and/or "git commit -a")

Correct. The commit you are applying the change with cherry-pick has etc/file different from the parent of the commit being cherry-picked, and the commit being cherry-picked also has it different, hence "both modified".

> git diff shows a lot of changes:
> ...

Again correct; it is showing the mechanical (half)merge result so that you know where you had overlapping changes. The comparison between an unmerged index and the working tree shows the changes in the file in the working tree with respect to both versions (the one in the commit you are on, and the other one in the commit you are cherry-picking), omitting parts that the file in the working tree match one of the versions. This is how you don't have to see any part of the file that was trivially merged in the output.

Show 13 quoted lines
> If I edit the file and remove the "<<<< HEAD" marked and code
> between "===" and ">>>"  then
>
> 1. git status shows there are unmerged files:
>
> $ git status
> # On branch 9_0
> # Unmerged paths:
> #   (use "git add/rm <file>..." as appropriate to mark resolution)
> #
> #	both modified:      etc/file
> #
> no changes added to commit (use "git add" and/or "git commit -a")

Correct; until you "git add" to mark the conflict resolved, the path is unmerged (do not ignore instructions in parentheses).

Show 7 quoted lines
> 2. git diff shows nothing:
>
> $ git diff
> diff --cc etc/file
> index 815c28f,b8a48da..0000000
> --- a/etc/file
> +++ b/etc/file

Again, correct. Read the description above on the "git diff" output. At this point, you removed the parts that came from one side (cherry-picked side) by removing the lines between "===" and ">>>", so the lines in the file in the working tree around that place match the other side (the one in the commit you are on). There is no block of lines that do not match one of the sides, so there is no combined diff to show.

> 3. git diff --cached shows error? warning? info?
>
> $ git diff --cached
> * Unmerged path etc/file

Correct. It is showing that you haven't run "git add" to resolve the path, so it still is unmerged.

> 4. When I git add the file then git status, git diff, git diff
> --cached shows nothing:

Correct. "git diff" is about comparing between the version in the index you recorded with "git add" and the file in the working tree, so there is nothing to show. "git diff --cached [HEAD]" compares the index and the HEAD, and it is understandable the result in the index matches HEAD if you discarded what came from the cherry-pick before step 1.

Show 12 quoted lines
> But when I take a different approach, and in addition to this:
>
>> If I edit the file and remove the "<<<< HEAD" marked and code
>> between "===" and ">>>"  then
>
> I also manually add the "+line" which is the change done in the cherry-picked
> commit, git diff shows a lot of other changes in unrelated lines
> (which lie close
> but still were not modified by the patch, nor were shown previously by
> git diff).
>
> This is very weird.
Sorry, I have no idea what you are talking about.
Previous: Piotr KrukowieckiNext: Johannes Sixt
Message 2 of 13 in “cherry-pick applies some other changes than the specified one?”
  1. Piotr KrukowieckiMar 21, 2011
  2. Junio C HamanoMar 21, 2011
  3. Johannes SixtMar 21, 2011
  4. Piotr KrukowieckiMar 21, 2011
  5. Junio C HamanoMar 21, 2011
  6. Piotr KrukowieckiMar 21, 2011
  7. Jonathan NiederMar 21, 2011
  8. Piotr KrukowieckiMar 21, 2011
  9. Junio C HamanoMar 21, 2011
  10. Junio C HamanoMar 21, 2011
  11. Jonathan NiederMar 22, 2011
  12. Junio C HamanoMar 22, 2011
  13. Piotr KrukowieckiMar 22, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.