有没有办法使用git查看文件的所有版本?(Is there a way to see all the versions of a file using git?)

我经常需要在旧版本的脚本中找到我编码的内容,但我不知道何时。 我经常尝试在日志中跳转,找到不同的版本,看看他们是否有变化,或者我只是放弃并尝试别的东西。

特别有用的是在两个日期或散列之间输出文件的每个版本的命令。 然后一个简单的grep会找到我正在寻找的东西。

它可能会像这样工作:

git showeverything d612905a..b39af32e /path/to/file /tmp/output

I often have a need to find something I coded in an old version of script but I don't know when. I usually try to jump around in the log finding different versions and seeing if they have the change, or I just give up and try something else.

What would be particularly useful is a command that outputs every version of a file between two dates or hashes. Then an easy grep would find what I'm looking for.

It would probably work something like this:

git showeverything d612905a..b39af32e /path/to/file /tmp/output

最满意答案

git有一个完美的工具: git log -S将搜索更改并仅显示这些提交

# search changes in all branches which touch the string $abc in a file git log -p -S'$abc' --all -- path/to/file

git has the perfect tool for this: git log -S which will search for a change and only show those commits

# search changes in all branches which touch the string $abc in a file git log -p -S'$abc' --all -- path/to/file

更多推荐