查找修改与 GIT 存储库中的模式匹配的文件名的提交

发布于 2024-11-17 02:13:12 字数 136 浏览 5 评论 0原文

我想在我的代码库中找到添加视频文件的提交以将其丢弃。 有没有办法在 git 中查找这些文件?

例如,假设所有视频的文件名都以扩展名 .wmv 结尾;我想找到引入这些文件的所有提交,并通过修复或其他方式删除它们。

有什么想法吗?

I'd like to find commits in my code base that add video files to throw them out.
Is there a way to look for these files in git ?

For example let's say all videos have a filename ending with the extension .wmv ; I'd like to find all commits introducing these files and get rid of them with a fixup or something.

Any ideas ?

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

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

发布评论

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

评论(7

窗影残 2024-11-24 02:13:12

您可以将 git log 与路径规范一起使用:

git log --all -- '*.wmv'

这将获取对 .wmv 文件进行更改的所有提交。是的,这也会下降到子目录中(并且您必须用单引号将路径规范引起来,以防止它被 shell 扩展;否则通配符将不会传递到 Git,而只会传递到文件名的扩展列表)。

如果您只对提交哈希(脚本等)感兴趣,请使用 git rev -list 直接机械:

git rev-list --all -- '*.wmv'

在 Windows 下,可能需要在路径规范周围使用双引号而不是单引号,即 "*.wmv"

You can use git log with a pathspec:

git log --all -- '*.wmv'

This will get you all commits which make changes to .wmv files. Yes, this will descend into subdirectories too (and you have to surround your pathspec with single quotes to protect it from being expanded by your shell; otherwise the wildcard will not be passed to Git, but only the expanded list of file names).

If you are only interested in commit hashes (scripting etc.) use the git rev-list machinery directly:

git rev-list --all -- '*.wmv'

Under Windows, it might be required to use double quotes instead of single quotes around the pathspec, i.e. "*.wmv"

苍风燃霜 2024-11-24 02:13:12

如果您想从所有提交中删除这些文件,请考虑使用 filter-branch 命令重写整个历史记录。例如,

git filter-branch --index-filter 'git rm --cached --ignore-unmatch -r *.wml' HEAD

If you want to remove these files from all your commits, consider rewriting the entire history with the filter-branch command. E.g.,

git filter-branch --index-filter 'git rm --cached --ignore-unmatch -r *.wml' HEAD
简美 2024-11-24 02:13:12

如果目标是从存储库中删除文件(从而重写历史记录),请使用 BFG Repo -Cleaner,例如:

bfg --delete-files '*.wmv' --private --no-blob-protection

如果文件相关,您可以使用 Git 将它们置于版本控制之下LFS。 操作:

git-lfs-migrate \
    -s original.git  \
    -d converted.git \
    -l https://user:[email protected]:8080 \
    '*.wmv'

迁移(也重写历史记录),您可以执行以下 检查提交,我参考 knittl 的答案:

git rev-list --all -- '*.wmv'
git log --all -- '*.wmv'

If the goal is to remove the files from the repository (thus rewriting history), use the BFG Repo-Cleaner, e.g.:

bfg --delete-files '*.wmv' --private --no-blob-protection

If the files are relevant, you can keep them under version control using Git LFS. To migrate (also rewriting history), you do something such as:

git-lfs-migrate \
    -s original.git  \
    -d converted.git \
    -l https://user:[email protected]:8080 \
    '*.wmv'

To simply list or examine the commits, I refer to knittl's answer:

git rev-list --all -- '*.wmv'
git log --all -- '*.wmv'
情话已封尘 2024-11-24 02:13:12

您可以尝试这样做:

git log --follow *.wmv

这将列出修改 wmv 文件的所有提交(带有哈希值)。

You can try this:

git log --follow *.wmv

this will list all commits (with hash) that modified wmv files.

奈何桥上唱咆哮 2024-11-24 02:13:12

是的,就像提到的,我认为删除引入它们的提交不会删除 blob

请参阅 http://progit.org/book/ch9-7.html#removing_objects 对主题和示例进行了广泛的处理

Yup, like mentioned, I think the thinko is that removing the commits that introduce them is not going to remove the blobs

See http://progit.org/book/ch9-7.html#removing_objects for an extensive treatment of the subject and examples

可爱咩 2024-11-24 02:13:12

这也可以在 gitk 中使用,使用“查看/新建视图/输入要包含的文件和目录,每行一个”框。

但请注意,您需要一个通配符来覆盖文件名的路径部分,否则将不会显示任何内容。

例如,如果您有一个名为 backup-script.sh 的文件,其生命周期 (!) 出现在文件树的不同位置,并且您想要查看所有版本,那么您必须指定:

*/backup-script.sh

This can work in gitk as well, using the View / New View / Enter files and directories to include, one per line box.

But note that you need a wildcard that covers the path section of the filename, or else nothing will show.

eg if you have had a file called backup-script.sh, with a varied life (!) appearing in different places in the file tree and you want to see all versions, then you must specify:

*/backup-script.sh
以歌曲疗慰 2024-11-24 02:13:12

要仅查看提交哈希值和每个提交的相关文件名,您可以使用:

git rev-list --all -- '*.wmv' $1 | while read x; do git diff-tree --name-only -r $x; done | grep -E '((\.wmv$)|(^[^\.]+$))'

这将打印出提交哈希值,后跟与搜索字符串匹配的任何文件名。

To just view the commit hashes and the relevant file names for each commit you can use:

git rev-list --all -- '*.wmv' $1 | while read x; do git diff-tree --name-only -r $x; done | grep -E '((\.wmv$)|(^[^\.]+$))'

This will print out the commit hash followed by any filenames that matching the search string.

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