Programing

Git에서 대소 문자를 구분하는 파일 이름 만 변경하려면 어떻게해야합니까?

lottogame 2020. 9. 27. 12:38
반응형

Git에서 대소 문자를 구분하는 파일 이름 만 변경하려면 어떻게해야합니까?


나는에 의해 몇 개의 파일 이름을 변경 한에서와 같이 첫 글자, 드 활용 Name.jpg하는 방법에 대해 name.jpg. Git은이 변경 사항을 인식하지 못하므로 파일을 삭제하고 다시 업로드해야했습니다. 파일 이름의 변경 사항을 확인할 때 Git에서 대소 문자를 구분할 수있는 방법이 있습니까? 파일 자체를 변경하지 않았습니다.


git mv 사용할 수 있습니다 .

git mv -f OldFileNameCase newfilenamecase

Git에는 대소 문자 구분 여부를 알려주는 구성 설정이 있습니다 : core.ignorecase. Git에 대소 문자를 구분하려면이 설정을 false다음과 같이 설정하면됩니다 .

git config core.ignorecase false

선적 서류 비치

로부터 git config문서 :

core.ignorecase

true 인 경우이 옵션을 사용하면 FAT와 같이 대소 문자를 구분하지 않는 파일 시스템에서 git이 더 잘 작동하도록 다양한 해결 방법을 사용할 수 있습니다. 예를 들어 디렉토리 목록에서 makefilegit이 예상하는시기를 찾으면 Makefilegit은 해당 파일이 실제로 동일한 파일이라고 가정하고 계속해서 Makefile.

기본값은 false이며, git-clone (1) 또는 git-init (1)core.ignorecase저장소가 생성 될 때 적절한 경우 true로 설정 합니다.

대소 문자를 구분하지 않는 파일 시스템

내가 알고있는 대소 문자를 구분하지 않는 파일 시스템을 가진 가장 널리 사용되는 두 운영 체제는 다음과 같습니다.

  • 윈도우
  • OS X

SourceTree를 사용하여 UI에서이 모든 작업을 수행 할 수있었습니다.

  1. 이름 바꾸기 FILE.extwhatever.ext
  2. 스테이지 해당 파일을
  3. 이제 이름 whatever.extfile.ext
  4. 스테이지 다시 파일을

약간 지루하지만 몇 개의 파일에만 필요한 경우 매우 빠릅니다.


이것이 내가 OS X에서 한 일입니다.

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

그렇지 않으면 "파일이 존재 함"오류가 발생했기 때문에 두 단계가 있습니다. 아마도 추가 --cached등을 통해 한 단계로 수행 할 수 있습니다 .


OSX에서는이 문제를 방지하고 대소 문자를 구분하지 않는 파일 시스템에서 개발할 때 발생하는 다른 문제를 방지하기 위해 디스크 유틸리티를 사용하여 대소 문자를 구분하는 가상 드라이브 / 디스크 이미지 만들 수 있습니다 .

디스크 유틸리티를 실행하고 새 디스크 이미지를 만들고 다음 설정을 사용합니다 (또는 원하는대로 변경하되 대소 문자를 구분합니다).

Mac 디스크 유틸리티 스크린 샷

이제 대소 문자를 구분하는 FS에 있다고 git에게 알려주십시오.

git config core.ignorecase false

때때로 Git의 대소 문자 구분 일시적으로 변경하는 것이 유용 할 수 있습니다 . 두 가지 가능한 방법 :-

Method 1 (change case sensitivity for a single command):

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 (change case sensitivity for multiple commands):

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.

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

If your repository is hosted remotely (GitHub, GitLab, BitBucket), you can rename the file on origin (GitHub.com) and force the file rename in a top-down manner.

The instructions below pertain to GitHub, however the general idea behind them should apply to any remote repository-hosting platform. Keep in mind the type of file you're attempting to rename matters, that is, whether it's a file type that GitHub deems as editable (code, text, etc) or uneditable (image, binary, etc) within the browser.

  1. Visit GitHub.com
  2. Navigate to your repository on GitHub.com and select the branch you're working in
  3. Using the site's file navigation tool, navigate to the file you intend to rename
  4. Does GitHub allow you to edit the file within the browser?
    • a.) Editable
      1. Click the "Edit this file" icon (it looks like a pencil)
      2. Change the filename in the filename text input
    • b.) Uneditable
      1. Open the "Download" button in a new tab and save the file to your computer
      2. Rename the downloaded file
      3. In the previous tab on GitHub.com, click the "Delete this file" icon (it looks like a trashcan)
      4. Ensure the "Commit directly to the branchname branch" radio button is selected and click the "Commit changes" button
      5. Within the same directory on GitHub.com, click the "Upload files" button
      6. Upload the renamed file from your computer
  5. Ensure the "Commit directly to the branchname branch" radio button is selected and click the "Commit changes" button
  6. Locally, checkout/fetch/pull the branch
  7. Done

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

Similar to @Sijmen's answer, this is what worked for me on OSX when renaming a directory (inspired by this answer from another post):

git mv CSS CSS2
git mv CSS2 css

Simply doing git mv CSS css gave the invalid argument error: fatal: renaming '/static/CSS' failed: Invalid argument perhaps because OSX's file system is case insensitive

p.s BTW if you are using Django, collectstatic also wouldn't recognize the case difference and you'd have to do the above, manually, in the static root directory as well


I used those following steps:

git rm -r --cached .
git add --all .
git commit -a -m "Versioning untracked files"
git push origin master

For me is a simple solution


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?


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

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.


If nothing worked use git rm filename to delete file from disk and add it back.


I took @CBarr answer and wrote a Python 3 Script to do it with a list of files:

#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

import os
import shlex
import subprocess

def run_command(absolute_path, command_name):
    print( "Running", command_name, absolute_path )

    command = shlex.split( command_name )
    command_line_interface = subprocess.Popen( 
          command, stdout=subprocess.PIPE, cwd=absolute_path )

    output = command_line_interface.communicate()[0]
    print( output )

    if command_line_interface.returncode != 0:
        raise RuntimeError( "A process exited with the error '%s'..." % ( 
              command_line_interface.returncode ) )

def main():
    FILENAMES_MAPPING = \
    [
        (r"F:\\SublimeText\\Data", r"README.MD", r"README.md"),
        (r"F:\\SublimeText\\Data\\Packages\\Alignment", r"readme.md", r"README.md"),
        (r"F:\\SublimeText\\Data\\Packages\\AmxxEditor", r"README.MD", r"README.md"),
    ]

    for absolute_path, oldname, newname in FILENAMES_MAPPING:
        run_command( absolute_path, "git mv '%s' '%s1'" % ( oldname, newname ) )
        run_command( absolute_path, "git add '%s1'" % ( newname ) )
        run_command( absolute_path, 
             "git commit -m 'Normalized the \'%s\' with case-sensitive name'" % (
              newname ) )

        run_command( absolute_path, "git mv '%s1' '%s'" % ( newname, newname ) )
        run_command( absolute_path, "git add '%s'" % ( newname ) )
        run_command( absolute_path, "git commit --amend --no-edit" )

if __name__ == "__main__":
    main()

참고 URL : https://stackoverflow.com/questions/17683458/how-do-i-commit-case-sensitive-only-filename-changes-in-git

반응형