How do I commit case-sensitive only filename chang

2018-12-31 12:59发布

问题:

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.

回答1:

You can use git mv:

git mv -f OldFileNameCase newfilenamecase


回答2:

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


回答3:

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.



回答4:

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



回答5:

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

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

git config core.ignorecase false


回答6:

1) rename file Name.jpg to name1.jpg

2) commit removed file Name.jpg

3) rename file name1.jpg to name.jpg

4) ammend added file name.jpg to previous commit

git add
git commit --amend


回答7:

It can sometimes be useful to temporarily change Git\'s case sensitivity. Two possible methods:-

Method 1:

git -c core.ignorecase=true checkout mybranch to turn off case-sensitivity for a single checkout command. Or more generally: git -c core.ignorecase= <<true or false>> <<command>>. (Credit to VonC for suggesting this in the comments.)

Method 2:

To change the setting for longer (e.g. if multiple commands need to be run before changing it back):

  1. git config core.ignorecase (this returns the current setting, e.g. false).
  2. git config core.ignorecase <<true or false>> - set the desired new setting.
  3. ...Run multiple other commands...
  4. git config core.ignorecase <<false or true>> - set config value back to its previous setting.


回答8:

I tried the following solutions from the other answers and they didn\'t work:

  • git mv filename
  • git rm -f filename

If your repository is hosted on GitHub like mine is, you can rename the file on origin (GitHub.com) and force the file rename in a top-down manner. Here\'s what I did:

  1. Visit GitHub.com
  2. Navigate to your repository on GitHub.com and select the branch you\'re working in
  3. Navigate to the file you intend to rename using the site\'s file navigation tool
  4. Click the \"Edit this file\" icon (it looks like a pencil)
  5. Change the filename in the filename text input
  6. Ensure the \"Commit directly to the branchname branch\" radio button is selected
  7. Click the \"Commit changes\" button
  8. Locally, checkout/pull/fetch the branch
  9. Done


回答9:

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

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



回答10:

I\'ve faced this issue several times on MacOS. Git is case sensitive but Mac is only case preserving.

Someone commit a file: Foobar.java and after a few days decides to rename it to FooBar.java. When you pull the latest code it fails with The following untracked working tree files would be overwritten by checkout...

The only reliable way that I\'ve seen that fixes this is:

  1. git rm Foobar.java
  2. Commit it with a message that you cannot miss git commit -m \'TEMP COMMIT!!\'
  3. Pull
  4. This will pop up a conflict forcing you to merge the conflict - because your change deleted it, but the other change renamed (hence the problem) it
    1. Accept your change which is the \'deletion\'
    2. git rebase --continue
  5. Now drop your workaround git rebase -i HEAD~2 and drop the TEMP COMMIT!!
  6. Confirm that the file is now called FooBar.java


回答11:

When you\'ve done a lot of file renaming and some of it are just a change of casing, it\'s hard to remember which is which. manually \"git moving\" the file can be quite some work. So what I would do during my filename change tasks are:

  1. remove all non-git files and folder to a different folder/repository.
  2. commit current empty git folder (this will show as all files deleted.)
  3. add all the files back into the original git folder/repository.
  4. commit current non-empty git folder.

This will fix all the case issues without trying to figure out which files or folders you renamed.