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

Re: Rename edge case...

From
TCTomas Carnecky <tomas.carnecky@gmail.com>
Date
Nov 9, 2012, 09:27 UTC
Message-ID
<1352453243-ner-1164@calvin>
In-Reply-To
<CAEBDL5U+OSTCAqgWoApE_m21Nef24Wqvt78oB6qqV4oEvU0vXQ@mail.gmail.com>
On Fri, 09 Nov 2012 04:10:31 -0500, John Szakmeister <john@szakmeister.net> wrote:
Show 21 quoted lines
> I've been browsing StackOverflow answering git-related questions, and
> ran across this one:
>     <http://stackoverflow.com/questions/13300675/git-merge-rename-conflict>
> 
> It's a bit of an interesting situation.  The user did a couple of
> renames in a branch:
>     foo.txt => fooOld.txt
>     fooNew.txt => foo.txt
> 
> Meanwhile, master had an update to fooNew.txt.  When the user tried to
> merge master to the branch, it gave a merge conflict saying fooNew.txt
> was deleted, but master tried to update it.
> 
> I was a bit surprised that git didn't follow the rename here, though I
> do understand why: git only sees it as a rename if the source
> disappears completely.  So I played locally with a few ideas, and was
> surprised to find out that even breaking up the two renames into two
> separate commits git still didn't follow it.
> 
> I'm just curious--I don't run into this often myself--but is there a
> good strategy for dealing with this that avoids the conflict?

When merging two branches, git only looks at the tips. It doesn't inspect their histories to see how the files were moved around. So i doesn't matter whether you rename the files in a single commit or multiple commits. The resulting tree is always the same.

tom
Previous: John SzakmeisterNext: John Szakmeister
Message 2 of 7 in “Rename edge case...”
  1. John SzakmeisterNov 9, 2012
  2. Tomas CarneckyNov 9, 2012
  3. John SzakmeisterNov 9, 2012
  4. Nguyen Thai Ngoc DuyNov 9, 2012
  5. Johannes SixtNov 9, 2012
  6. Jeff KingNov 9, 2012
  7. John SzakmeisterNov 10, 2012

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.