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

前端 未结 16 2282
我在风中等你
我在风中等你 2020-11-22 03:31

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 de

相关标签:
16条回答
  • 2020-11-22 03:54

    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/

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

    0 讨论(0)
  • 2020-11-22 03:54

    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
    0 讨论(0)
  • 2020-11-22 03:55

    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
    
    0 讨论(0)
  • 2020-11-22 03:55

    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.

    0 讨论(0)
  • 2020-11-22 03:56

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

    1. Rename FILE.ext to whatever.ext
    2. Stage that file
    3. Now rename whatever.ext to file.ext
    4. 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

    0 讨论(0)
  • 2020-11-22 03:59

    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
    0 讨论(0)
提交回复
热议问题