Changing capitalization of filenames in Git

前端 未结 9 1772
孤独总比滥情好
孤独总比滥情好 2020-11-22 14:02

I am trying to rename a file to have different capitalization from what it had before:

git mv src/collision/b2AABB.js src/collision/B2AABB.js
fatal: destinat         


        
9条回答
  •  天涯浪人
    2020-11-22 14:29

    This Python snippet will git mv --force all files in a directory to be lowercase. For example, foo/Bar.js will become foo/bar.js via git mv foo/Bar.js foo/bar.js --force.

    Modify it to your liking. I just figured I'd share :)

    import os
    import re
    
    searchDir = 'c:/someRepo'
    exclude = ['.git', 'node_modules','bin']
    os.chdir(searchDir)
    
    for root, dirs, files in os.walk(searchDir):
        dirs[:] = [d for d in dirs if d not in exclude]
        for f in files:
            if re.match(r'[A-Z]', f):
                fullPath = os.path.join(root, f)
                fullPathLower = os.path.join(root, f[0].lower() + f[1:])
                command = 'git mv --force ' + fullPath + ' ' + fullPathLower
                print(command)
                os.system(command)
    

提交回复
热议问题