在Git中,如何通过多个分支中的路径搜索文件或目录?
我已经在分支中写了一些东西,但我不记得是哪个。现在我需要找到它。
澄清:我正在寻找我在其中一个分支上创建的文件。我想通过路径而不是内容来查找它,因为我不记得内容是什么。
最佳答案
git log
+ git branch
将为您找到它:
% git log --all -- somefile
commit 55d2069a092e07c56a6b4d321509ba7620664c63
Author: Dustin Sallings <dustin@spy.net>
Date: Tue Dec 16 14:16:22 2008 -0800
added somefile
% git branch -a --contains 55d2069
otherbranch
也支持滚动:
% git log --all -- '**/my_file.png'
单引号是必需的(至少在使用Bash shell的情况下),因此shell会将glob模式传递给git而不更改git,而不是扩展它(就像Unix
find
一样)。