git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Tomas Carnecky <tom@dbservice.com>
To: git mailing list <git@vger.kernel.org>
Subject: Git confused when file is renamed/renamed+modified and result merged
Date: Fri, 5 Jun 2009 22:06:04 +0200	[thread overview]
Message-ID: <B88C71A7-5EDB-4DAC-9288-E1C700C255DA@dbservice.com> (raw)

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

                 reply	other threads:[~2009-06-05 20:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=B88C71A7-5EDB-4DAC-9288-E1C700C255DA@dbservice.com \
    --to=tom@dbservice.com \
    --cc=git@vger.kernel.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).