在git中批量重命名文件为小写

发布于 2024-12-06 16:05:36 字数 276 浏览 2 评论 0原文

我有一个完整的 git 存储库,我想将所有文件和目录重命名为小写。

在Win7上运行,我在gitconfig中添加了igorecase = false,并通过eclipse重命名了一些文件。生成的提交现在有两个文件,一个全小写,另一个同时大写和小写。

删除“不需要的”文件会转储不理想的版本历史记录...

那么实现我的目标的潜在方法是什么 - 认为唯一的选择是批处理/shell(不知道如何在那里执行递归目录内容,但希望有人会友善一点;))

收到的任何提示都深表感谢和拥抱。

I have an entire git repo where I'd like to rename all the files and direcories to lowercase.

Running on Win7, I've added igorecase = false to the gitconfig and renamed a few files through eclipse. The resulting commit now has the two files, one all lowercase and one with upper and lowecase.

Removing the 'undesired' file would dump the version history which is not ideal...

So what is potential method to achieve my goal - thinking only option is batch/shell (not sure how to do recursive directory stuff in there but hopefully someone will be kind ;) )

Any tips recieved with massive thanks and hugs.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

岛徒 2024-12-13 16:05:36

当我不得不更改 git 存储库中文件的大小写时,我只使用两个重命名:

git mv aNiceClass.inc aniceclass.inc_
git mv aniceclass.inc_ aniceclass.inc

Git 然后愉快地记录名称更改:

# Changes to be committed:
#
#   renamed:    aNiceClass.inc -> aniceclass.inc

尝试直接重命名会引发此错误:

fatal: destination exists, source=aNiceClass.inc, destination=aniceclass.inc

这是一个示例 shell 脚本,它将小写任何名称当前目录下具有 inctxt 文件扩展名的文件:

#! /bin/bash

find -E . -regex '.*(inc|txt)

也可以将其混入丑陋的小单行代码中:

find -E . -regex '.*(inc|txt)
 | while read f
do
   lc=$(echo ${f} | tr A-Z a-z)
   git mv $f ${lc}_
   git mv ${lc}_ $lc
done

也可以将其混入丑陋的小单行代码中:


 | while read f; do lc=$(echo ${f} | tr A-Z a-z); git mv $f ${lc}_; git mv ${lc}_ $lc; done
| while read f do lc=$(echo ${f} | tr A-Z a-z) git mv $f ${lc}_ git mv ${lc}_ $lc done

也可以将其混入丑陋的小单行代码中:

When I've had to change case of files in a git repo I just use two renames:

git mv aNiceClass.inc aniceclass.inc_
git mv aniceclass.inc_ aniceclass.inc

Git then happily records the name change:

# Changes to be committed:
#
#   renamed:    aNiceClass.inc -> aniceclass.inc

Trying to do the rename directly throws this error:

fatal: destination exists, source=aNiceClass.inc, destination=aniceclass.inc

Here's an example shell script which will lowercase the name of any file below the current directory which has an inc or txt file extension:

#! /bin/bash

find -E . -regex '.*(inc|txt)

That could also be mashed in an ugly little one-liner:

find -E . -regex '.*(inc|txt)
 | while read f
do
   lc=$(echo ${f} | tr A-Z a-z)
   git mv $f ${lc}_
   git mv ${lc}_ $lc
done

That could also be mashed in an ugly little one-liner:


 | while read f; do lc=$(echo ${f} | tr A-Z a-z); git mv $f ${lc}_; git mv ${lc}_ $lc; done
| while read f do lc=$(echo ${f} | tr A-Z a-z) git mv $f ${lc}_ git mv ${lc}_ $lc done

That could also be mashed in an ugly little one-liner:

生生不灭 2024-12-13 16:05:36

由于标题或标签没有提及任何有关操作系统的内容,因此这适用于 macOS。它执行 git mv 将文件夹中的所有文件转为小写。如果您需要强制标志,只需将其添加到 git mv 后面即可。

for f in *; do git mv "$f" "`echo $f | tr "[:upper:]" "[:lower:]"`"; done

Since the title or tags doesn't mention anything about OS, this works on macOS. It does a git mv to lowercase on all files in a folder. If you need the force flag just add it in after git mv.

for f in *; do git mv "$f" "`echo $f | tr "[:upper:]" "[:lower:]"`"; done
深海夜未眠 2024-12-13 16:05:36

对于初学者来说,core.ignorecase 默认情况下为 false。

您的提交应该列出两个文件,一个用于删除,一个用于添加。
提交后,Git 会检测到其中一个已重命名为另一个
(因为 Git 的核心是一个内容提供者< /a>)。
历史记录将被保留(即使您可能需要 git log --follow -- yourNewFile 才能获取其历史记录)

注意:git 2.0.1 现在授权一个简单的 git mv a .txt A.txt:请参阅“Git:更改文件名的大小写”。
不再需要像下面这样的脚本

For starter, core.ignorecase is false by default.

And your commit should have the two files listed, but one for removal, and one for addition.
Upon commit, Git will detect that one has been renamed into the other
(since Git is at its core a content provider).
The history will be preserved (even though you might need a git log --follow -- yourNewFile in order to get its history)

Note: git 2.0.1 authorizes now a simple git mv a.txt A.txt: see "Git: Changing capitalization of filenames".
No more need for a script like the one below.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文