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 13:03

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

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
查看更多
姐姐魅力值爆表
3楼-- · 2018-12-31 13:05

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
查看更多
大哥的爱人
4楼-- · 2018-12-31 13:06

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
查看更多
倾城一夜雪
5楼-- · 2018-12-31 13:06

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.
查看更多
只若初见
6楼-- · 2018-12-31 13:10

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.

查看更多
登录 后发表回答