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

Rename of file is causing changes to be lost

From
RDRobert Dailey <rcdailey.lists@gmail.com>
Date
Mar 8, 2018, 16:01 UTC
Message-ID
<CAHd499Axo7HFviUJavigTZ6BGZCkj9iOSeNVndu1oPivkPv+5Q@mail.gmail.com>

I'm on Windows and core.ignorecase is set to 'true' when I clone/init a repository. I've got a branch where I started making changes to a file AND renamed it only to change its case. The changes I've made were significant enough that git no longer detects a rename, instead the files show up as "D" and "A" in git status (deleted then added). To correct this, I do an interactive rebase to add an additional commit before the first one to rename the file without changing it, and *then* allow the second commit to change the file. The goal is that rebase should detect the rename and automatically move the changes in the (now) second commit to the newly named file. Here's a MCVE (treat this as a script):

#/bin/bash git init testgitrepo cd testgitrepo/ git config core.ignorecase true # This is set by Windows for me, but hopefully will allow this to repro on linux. Didn't test linux though. echo "first change" > foo.txt git add . && git commit -m 'first change' git checkout -b topic echo "second change" > foo.txt git mv foo.txt FOO.txt git add . && git commit -m 'second change' git rebase -i master # Move line 1 to line 2, and put "x false" in line 1 git mv foo.txt FOO.txt && git commit -m 'rename foo' git rebase --continue git mergetool

After the rebase continue, you will get a conflict like so:
error: could not apply 527d208... second change

When you have resolved this problem, run "git rebase --continue". If you prefer to skip this patch, run "git rebase --skip" instead. To check out the original branch and stop rebasing, run "git rebase --abort".

Could not apply 527d208... second change CONFLICT (rename/delete): foo.txt deleted in 527d208... second change and renamed to FOO.txt in HEAD. Version HEAD of FOO.txt left in tree.

The last command, `git mergetool` runs, giving you the option to pick the Created (left) or Deleted (right) version of the file:

Left: The file is created, but selecting this erases the changes from
the "added" version on the remote (which is topic). Basically the
rename of only case confused git, and we lost the changes on the
remote version of the file
Right: File is deleted. Changes are still lost.

The ideal outcome is that the changes from the "added" version of the file in the 2nd commit get carried over to the "renamed" version of the file, which when you compare the two are named exactly the same after the 1st commit is introduced. How can I solve this issue?

Next: Robert Dailey
Message 1 of 4 in “Rename of file is causing changes to be lost”
  1. Robert DaileyMar 8, 2018
  2. Robert DaileyMar 13, 2018
  3. Elijah NewrenMar 13, 2018
  4. Robert DaileyMar 13, 2018

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.