How do I commit case-sensitive only filename chang

2018-12-31 12:09发布

I have changed a few files name by de-capitalize the first letter, as in Name.jpg to name.jpg. Git does not recognize this changes and I had to delete the files and upload them again. Is there a way that Git can be case-sensitive when checking for changes in file names? I have not made any changes to the file itself.

11条回答
何处买醉
2楼-- · 2018-12-31 12:46

You can use git mv:

git mv -f OldFileNameCase newfilenamecase
查看更多
其实,你不懂
3楼-- · 2018-12-31 12:48

Under OSX, to avoid this issue and avoid other problems with developing on a case-insensitive filesystem, you can use Disk Utility to create a case sensitive virtual drive / disk image.

Run disk utility, create new disk image, and use the following settings (or change as you like, but keep it case sensitive):

Mac Disk Utility Screenshot

Make sure to tell git it is now on a case sensitive FS:

git config core.ignorecase false
查看更多
唯独是你
4楼-- · 2018-12-31 12:49

Mac OSX High Sierra 10.13 fixes this somewhat. Just make a virtual APFS partition for your git projects, by default it has no size limit and takes no space.

  1. In Disk Utility, click the + button while the Container disk is selected
  2. Select APFS (Case-Sensitive) under format
  3. Name it Sensitive
  4. Profit
  5. Optional: Make a folder in Sensitive called git and ln -s /Volumes/Sensitive/git /Users/johndoe/git

Your drive will be in /Volumes/Sensitive/

enter image description here

How do I commit case-sensitive only filename changes in Git?

查看更多
泪湿衣
5楼-- · 2018-12-31 12:52

Git has a configuration setting that tells it whether to be case sensitive or insensitive: core.ignorecase. To tell Git to be case-senstive, simply set this setting to false:

git config core.ignorecase false

Documentation

From the git config documentation:

core.ignorecase

If true, this option enables various workarounds to enable git to work better on filesystems that are not case sensitive, like FAT. For example, if a directory listing finds makefile when git expects Makefile, git will assume it is really the same file, and continue to remember it as Makefile.

The default is false, except git-clone(1) or git-init(1) will probe and set core.ignorecase true if appropriate when the repository is created.

Case-insensitive file-systems

The two most popular operating systems that have case-insensitive file systems that I know of are

  • Windows
  • OS X
查看更多
春风洒进眼中
6楼-- · 2018-12-31 12:53

This is what I did on OS X:

git mv File file.tmp
git mv file.tmp file

Two steps because otherwise I got a “file exists” error. Perhaps it can be done in one step by adding --cached or such.

查看更多
ら面具成の殇う
7楼-- · 2018-12-31 13:02

Using SourceTree I was able to do this all from the UI

  • Rename FILE.ext to whatever.ext
  • Stage that file
  • Now rename whatever.ext to file.ext
  • Stage that file again

It's a bit tedious, but if you only need to do it to a few files it's pretty quick

查看更多
登录 后发表回答