搜索所有Git历史记录中的字符串? [重复]
This question already has an answer here: 这个问题在这里已有答案:How to grep Git commit diffs or cont
本文翻译自:Search all of Git history for a string? [duplicate]
This question already has an answer here: 这个问题在这里已有答案:
I have a code base which I want to push to GitHub as open source. 我有一个代码库,我想将其作为开源推送到GitHub。 In this git-controlled source tree, I have certain configuration files which contain passwords. 在这个git控制的源代码树中,我有一些包含密码的配置文件。 I made sure not to track this file and I also added it to the .gitignore
file. 我确保不跟踪此文件,我还将其添加到.gitignore
文件中。 However, I want to be absolutely positive that no sensitive information is going to be pushed, perhaps if something slipped in-between commits or something. 但是,我希望绝对肯定的是,没有任何敏感信息会被推送,也许是因为某些事情在提交之间滑落了。 I doubt I was careless enough to do this, but I want to be positive . 我怀疑我做得不够粗心,但我想要积极 。
Is there a way to "grep" all of git? 有没有办法“grep”所有的git? I know that sounds weird, but by "all" I mean every version of every file that ever existed. 我知道这听起来很奇怪,但“全部”我的意思是每个文件的每个版本都存在。 I guess if there is a command that dumps the diff file for every commit, that might work? 我想如果有一个命令为每次提交转储diff文件,那可能有用吗?
#1楼
参考:https://stackoom.com/question/IkQL/搜索所有Git历史记录中的字符串-重复
#2楼
Try the following commands to search the string inside all previous tracked files: 尝试使用以下命令搜索所有先前跟踪文件中的字符串:
git log --patch | less +/searching_string
or 要么
git rev-list --all | GIT_PAGER=cat xargs git grep 'search_string'
which needs to be run from the parent directory where you'd like to do the searching. 需要从您要进行搜索的父目录运行。
#3楼
git rev-list --all | (
while read revision; do
git grep -F 'password' $revision
done
)
#4楼
Git can search diffs with the -S option (it's called pickaxe in the docs ) Git可以使用-S选项搜索差异( 在文档中称为pickaxe)
git log -Spassword
This will find any commit that added or removed the string password
. 这将找到添加或删除字符串password
任何提交。 Here a few options: 这里有几个选择:
-
-p
: will show the diffs.-p
:将显示差异。 If you provide a file (-p file
), it will generate a patch for you. 如果您提供文件(-p file
),它将为您生成一个补丁。 -
-G
: looks for differences whose added or removed line matches the given regexp, as opposed to-S
, which "looks for differences that introduce or remove an instance of string".-G
:查找添加或删除的行与给定的正则表达式匹配的差异,而不是-S
,“查找引入或删除字符串实例的差异”。 -
--all
: searches over all branches and tags;--all
:搜索所有分支和标签; alternatively, use--branches[=<pattern>]
or--tags[=<pattern>]
或者,使用--branches[=<pattern>]
或--tags[=<pattern>]
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)