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

Git confused when file is renamed/renamed+modified and result merged

From
Tomas Carnecky <tom@dbservice.com>
Date
Jun 5, 2009, 20:06 UTC
Message-ID
<B88C71A7-5EDB-4DAC-9288-E1C700C255DA@dbservice.com>

I was helping someone on IRC with merge problems and it boiled down to this. Git is confused when one branch renames a file while another branch renames the file in the same way and then modifies the file. When merging the two branches git will indicate a conflict in the 'source' file (rename/delete) but not the 'destination' file and will put the destination file from the first branch into the working tree, even though the second branch has a file with the same name but conflicting contents.

Git commands that lead up to this situation, with interleaved comments. A usability suggestion is also included in the following transcript:

bash-3.2$ git --version
git version 1.6.3.2.198.g6096d
bash-3.2$ git init
Initialized empty Git repository in /Users/tomc/gitest/.git/
bash-3.2$ echo arst > file1
bash-3.2$ git add file1
bash-3.2$ git commit -m 'initial commit'
[master (root-commit) fdad65c] initial commit
  1 files changed, 1 insertions(+), 0 deletions(-)
  create mode 100644 file1
bash-3.2$ git branch new
# branch master renames the file without modifying it
bash-3.2$ git mv file1 file2
bash-3.2$ git commit -m 'move file1 to file2'
[master 053cc6f] move file1 to file2
  1 files changed, 0 insertions(+), 0 deletions(-)
  rename file1 => file2 (100%)
bash-3.2$ git checkout new
Switched to branch 'new'
# branch new moves the file while modifying it so heavily that git  
doesn't
# recognize it as a rename anymore
bash-3.2$ git rm file1
rm 'file1'
bash-3.2$ echo qwfp > file2
bash-3.2$ git add file2
bash-3.2$ git commit -m 'move file1 to file2, while heavily modifying  
it'
[new 4118625] rename file1 to file2, while heavily modifying it
  2 files changed, 1 insertions(+), 1 deletions(-)
  delete mode 100644 file1
  create mode 100644 file2

# merge new into master bash-3.2$ git checkout master Switched to branch 'master' bash-3.2$ git merge new

# Usability suggestion: Not clear to which file the 'deleted in new' is # referring to. Maybe change the message to: # CONFLICT in 'file1' (rename/delete): Renamed to file2 in HEAD, deleted in new. CONFLICT (rename/delete): Rename file1->file2 in HEAD and deleted in new Automatic merge failed; fix conflicts and then commit the result.

# as expected, there's a conflict in 'file1'. But 'file2' is silently accepted # from the 'master' branch, even though the 'new' branch has a file with the # same name but different contents bash-3.2$ git show :2:file2 arst bash-3.2$ git show :3:file2 fatal: ambiguous argument ':3:file2': unknown revision or path not in the working tree. Use '--' to separate paths from revisions bash-3.2$ git show new:file2 qwfp bash-3.2$

tom
Message 1 of 1 in “Git confused when file is renamed/renamed+modified and result merged”
  1. Tomas CarneckyJun 5, 2009

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.