Erfankam
Erfankam

Reputation: 387

Git file renaming produces Error: "warning: destination exists; will overwrite!"

I want to rename my file in my repository locally. So I do:

git mv -f hashpq.py HashPQ.py

And get this:

warning: destination exists; will overwrite!

Then I get the status of git by:

git status

And get thisresponse:

# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   deleted:    hashpq.py
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   hashpq.py

But after I list my directory by:

ls

I have this:

CHANGLELOG  hashpq.py  NEXTPLAN  README  TODO

I still have hashpq.py unchanged with previous name. How can I rename the file to HashPQ.py?

Upvotes: 4

Views: 3833

Answers (3)

VonC
VonC

Reputation: 1329092

You shouldn't need -f anymore, with git 2.0.1 (June 25yh, 2014).

A git mv hashpq.py HashPQ.py will just work on case insensitive OS, as detailed in commit baa37bf by David Turner (dturner-tw)

mv: allow renaming to fix case on case insensitive filesystems

"git mv hello.txt Hello.txt" on a case insensitive filesystem always triggers "destination already exists" error, because these two names refer to the same path from the filesystem's point of view, and requires the user to give "--force" when correcting the case of the path recorded in the index and in the next commit.

Detect this case and allow it without requiring "--force".

Upvotes: 1

Erfankam
Erfankam

Reputation: 387

My file system was NTFS and as you know it s case insensitive for file names basically. Thus, I need to first change it to asghar.py first and then change it to HashPQ.py.

Thanks all.

Upvotes: 0

Will Vousden
Will Vousden

Reputation: 33408

Try renaming it to some temporary name, and then to the name you want:

git mv hashpq.py _hashpq.py
git mv _hashpq.py HashPQ.py
git commit

This is the same behaviour as the regular mv command when the file system is case-insensitive.

Upvotes: 7

Related Questions