10

I want to rename SystemDBContext.cs to SystemDbContext.cs and when I try renaming the file like this:

git mv SystemDBContext.cs SystemDbContext.cs

I get the following error:

fatal: destination exists, source=BabyChangeFinder/DataAccess/SystemDBContext.cs, destination=BabyChangeFinder/DataAccess/SystemDbContext.cs

I checked the directory; the destination definitely doesn't exist:

$ ls
SystemDBContext.cs

Anyone know what's going on here?

NRKirby
  • 1,584
  • 4
  • 21
  • 38
  • use `mv SystemDBContext.cs System.DbContext.cs` without using `git` – Zaaferani Apr 19 '15 at 09:53
  • I want the rename tracked in git – NRKirby Apr 19 '15 at 09:57
  • What Git version are you using? This should work with Git 2.0.1+ (http://stackoverflow.com/a/24979063/6309) – VonC Apr 19 '15 at 09:57
  • Looks like I'm using `git version 1.9.5.msysgit.0` FYI I'm using windows and have been able to rename a file before? – NRKirby Apr 19 '15 at 09:59
  • 2
    `git mv --force` is no longer needed with git for Windows 2.3.5 (https://github.com/git-for-windows/git/releases) – VonC Apr 19 '15 at 10:05
  • 5
    @NRKirby just fyi, git does not track renaming files _explicitly_. `git mv` is only for convenience; see [here](https://git-scm.herokuapp.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository#Moving-Files); – behzad.nouri Apr 19 '15 at 12:57
  • 2
    @NRKirby you're running Windows, which is case-insensitive. When git goes to move the file to the new name, Windows tells it that there's already a file with that name, because the old name and the new name are the same as far as Windows can tell. – hobbs Apr 20 '15 at 18:22
  • @NRKirby: Thanks for editing the answer to match the corrected filenames. FYI, you don't need to call out yours edits with 'Edit by OP'. Just put the changes in. People who want to can look at the edit history and see who did what. Cheers! =) – Conspicuous Compiler Apr 20 '15 at 18:46
  • @ConspicuousCompiler: It wouldn't let me save the change I wanted as I was editing less than the minimum required character count, that's why I added the msg I did.. – NRKirby Apr 20 '15 at 19:31
  • 1
    @NRKirby: OIC. No worries, then. – Conspicuous Compiler Apr 20 '15 at 19:33

1 Answers1

9

Try

git mv --force SystemDBContext.cs SystemDbContext.cs

or

git mv -f SystemDBContext.cs SystemDbContext.cs

Conspicuous Compiler
  • 6,403
  • 1
  • 40
  • 52
Vaibhav Mule
  • 5,016
  • 4
  • 35
  • 52
  • 1
    Awesome!!, I think it can be done also in this way "mv -f filename.cs newfilename.cs " – Abhinay Apr 20 '15 at 16:44
  • I'm in year 2023, and using git `git version 2.40.0.windows.1`, and I have already run the command `git config --local core.ignorecase false`, but I still need the `--force` option. If not, I got the same issue as OP. – ollydbg23 Jul 09 '23 at 00:54