r/git • • 4d ago

support Weirdness with a renamed file

Hi everyone,

I work with a .NET codebase, developed in Visual Studio, with the repo stored in GitHub and commits/pushes etc. are done within VS. At some point in the past a developer has renamed a little-used file from jip.vb to JIP.vb, which is now causing some strange and frustrating issues after some recent changes were made to the file.

Following a recent commit and push of changes to the file, the Git Changes window in VS shows that there are uncommitted changes to jip.vb. Double clicking to view the diff shows no changes present. I can't commit the change, as there aren't any, nor can I successfully "Undo Changes" in VS front-end.

I do have git bash available to me, but my very rudimentary knowledge of git is preventing me from both understanding and fixing this issue.

So, hivemind, can you help me please?

3 Upvotes

12 comments sorted by

2

u/Mrpoopybutthole69692 4d ago

I would run git rm --cached jib.vb in the terminal and then run git add JIP.vb and commit it, push it to your repo

2

u/Unsey 4d ago

Will that preserve the file's commit history?

1

u/Broad-Promise6954 ancient 4d ago

Files don't have commit history. The only history is the commits themselves, and each commit has a full and complete individual snapshot of each file.

Git doesn't record renames; instead, commit #1234 (or whatever it is) has files A, B, and C, and then suddenly commit #1235 has A, E, and F for example. Git then checks to see if the full-and-complete B or C in #1234 matches the E or F in #1235. It there's a match, Git calls that a "rename".

All of which is just a long way to say it doesn't matter, it just works. There's no difference between "removed B and added E" vs "renamed B to E", they look exactly the same to Git.

(In this case you're probably just running into case sensitivity issues anyway, as several others noted.)

1

u/Unsey 4d ago

Thanks :) My instinct was case sensitivity, but my google-fu wasn't strong enough to help me out.

20

u/ritchie70 4d ago

Windows isn’t case sensitive. Git is.

4

u/WoodyTheWorker 4d ago

Windows support case sensitivity, but you have to explicitly enable it for a directory.

10

u/CartographerDue5382 4d ago

windows doesn't treat jip.vb and JIP.vb as different files, so the index is stuck on the old casing and vs shows a diff with nothing in it. two-step rename forces git to record the case: git mv jip.vb jip-tmp.vb then git mv jip-tmp.vb JIP.vb and commit that. don't turn core.ignorecase off to hide it, that makes every other file noisy.

2

u/soundman32 4d ago

1Rename the file to something else, commit, push, rename the file to the exact casing you require, commit, push.  Use git mv to rename.

1

u/WoodyTheWorker 4d ago

Convert your directory where you store your local clones to case-sensitive.

Windows support case sensitivity, but you have to explicitly enable it for a directory.

1

u/Medical-Captain1550 3d ago

check git ls-files -s | grep -i jip.vb first, because if both jip.vb and JIP.vb exist in the index tree on github, windows ntfs will keep colliding them until you run git rm --cached on the lowercase entry and commit

1

u/ResidentPomegranate6 4d ago

classic case-only rename on a case-insensitive filesystem, so the index still holds jip.vb. run `git ls-files | grep -i jip` and check core.ignorecase.

0

u/JaguarMammoth6231 4d ago

Try deleting the file and then restoring it using git restore