git - 如何搜索 repo 历史?

标签 git mercurial

有一个包含大量提交的 repo 协议(protocol)。我知道我正在寻找的文件的名称和东西(一个字符串,准确地说是一些系数),但我不知道它在什么提交中。它不再是当前的一个,这是肯定的,前面几个也没有。

*我如何按时间搜索指定文件(或整个存储库中,我不不在乎),所以它会遍历所有提交直到他找到它?*

对 mercurial 和 git 都感兴趣。目前两者都在使用,我真的不知道这是否适用于其中任何一个。

最佳答案

Mercurial 有 grep命令。来自文档:

hg grep [OPTION]... PATTERN [FILE]...

search for a pattern in specified files and revisions

Search revisions of files for a regular expression.

This command behaves differently than Unix grep. It only accepts
Python/Perl regexps. It searches repository history, not the working
directory. It always prints the revision number in which a match appears.

By default, grep only prints output for the first revision of a file in
which it finds a match. To get it to print every revision that contains a
change in match status ("-" for a match that becomes a non-match, or "+"
for a non-match that becomes a match), use the --all flag.

对于 Git,这个相关问题似乎很相关:

How to grep (search) committed code in the git history?

关于git - 如何搜索 repo 历史?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8099680/

相关文章:

r - 将文件提交到 GitHub 时,不会将用户名配置到 Git。而是使用 GitHub 的用户名。为什么会这样?

mercurial - 查找逻辑更改日志

visual-studio-2008 - 本地提交推送到中央服务器

mercurial - 在 Mercurial 中指定编辑器

mercurial - 我可以 "break"hg 工作副本,以便在提交之前必须将其恢复吗?

linux - 如何重新创建本地删除的文件?

git - 如何找到过去日期的 100 个最大的 GitHub 存储库?

git - 通过部分名称在git中切换分支

git - 防止修改 GitHub 中主分支上的文件

git - merge 后如何在git-lfs中修复Unity .prefab文件