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

Re: git merge questions

From
Junio C Hamano <junkio@cox.net>
Date
Dec 16, 2005, 22:17 UTC
Message-ID
<7voe3gd6ul.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<68948ca0512161335k50a3ec64lee6f73ea4f8ae23f@mail.gmail.com>
Don Zickus <dzickus@gmail.com> writes:
Show 20 quoted lines
>> and then, the digging I suggested yields these:
>>
>> $ ls -l arch/{ppc64,powerpc}/Kconfig
>> -rw-rw-r--  1 junio src 24279 Dec 16 12:55 arch/powerpc/Kconfig
>> -rw-rw-r--  1 junio src 11027 Dec 16 12:58 arch/ppc64/Kconfig
>> $ git ls-files -s arch/ppc64/Kconfig arch/powerpc/Kconfig
>> 100644 bb2efdd566a9d590d64184b10b097e4b7ed17e95 0       arch/powerpc/Kconfig
>> 100644 c658650af429672267409508b02b38754c11a40f 1       arch/ppc64/Kconfig
>> 100644 8abf1118ebbd59954d098d87679114ffda0e75cb 3       arch/ppc64/Kconfig
>> ..
>> The result you want in this case is to merge changes between
>> c65865 (stage1 of old path) and 8abf11 (stage3 of old path) into
>> bb2efd (the latest contents of the new path) and register it as
>> the result of merge for arch/powerpc/Kconfig, and remove
>> arch/ppc64/Kconfig.  So the sequence would be:
>>
>> $ orig=$(git unpack-file c65865)
>> $ from_test=$(git unpack-file 8abf11)
>> $ merge $from_test $orig arch/powerpc/Kconfig
>> merge: warning: conflicts during merge

I suspect there might be a room for improvement to make this easier with a new command, if this becomes a common pattern.

Something like:
	$ git resolve-renamed-path arch/ppc64/Kconfig arch/powerpc/Kconfig

to mean "I want the result of this merge to rename ppc64/Kconfig to powerpc/Kconfig", perhaps? There are three cases: (1) we renamed they didn't --- this is the case we are looking at and there will be stage1 and stage3 but not stage2 for the old path, and stage0 for the new path; (2) they renamed we didn't --- this would happen if you pulled test2 into test, and there will be stage1 and stage2 but not stage3 for the old path, and stage0 for the new path; (3) both of us renamed.

The third case is handled by the merge command automatically. Old path will not remain to bother you even if the merge of the new path needs hand-resolving, so you do not need resolve-renamed-path command to deal with that case.

Show 6 quoted lines
> Now say I didn't know the name of the rename and I had to dig
> that up.  Would the following be the right way or is there
> something easier?
>
> %git log <renamed file>  #grab the last commit id from here
> %git-diff-tree -p <last commit id>  # search for the new file
That would work.

Or an explicit rename detection to see where many of the neighbouring paths moved (this is very expensive):

	mb=$(git merge-base test test2)
        git diff-tree -r --diff-filter=R -M -l0 --name-status $mb test2

Or the diff-tree between the merge base and your current tree and perhaps the other tree (this may give a lot of cruft):

	mb=$(git merge-base test test2)
        git diff-tree -r --diff-filter=A --name-status $mb test2
Previous: Don ZickusNext: Johannes Schindelin
Message 6 of 9 in “git merge questions”
  1. Don ZickusDec 16, 2005
  2. Junio C HamanoDec 16, 2005
  3. Don ZickusDec 16, 2005
  4. Junio C HamanoDec 16, 2005
  5. Don ZickusDec 16, 2005
  6. Junio C HamanoDec 16, 2005
  7. Johannes SchindelinDec 16, 2005
  8. Junio C HamanoDec 17, 2005
  9. Junio C HamanoDec 17, 2005

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.