[英]Is there a way to see all the versions of a file using git?
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.
然后一个简单的grep会找到我正在寻找的东西。
It would probably work something like this: 它可能会像这样工作:
git showeverything d612905a..b39af32e /path/to/file /tmp/output
git has the perfect tool for this: git log -S
which will search for a change and only show those commits 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
I understand this may not be the answer you're looking for, but every git hosting website/service has a nice GUI do look through the commit history of every file in a repository. 我知道这可能不是您正在寻找的答案,但每个git托管网站/服务都有一个很好的GUI,可以查看存储库中每个文件的提交历史记录。 I use it a lot.
我经常使用它。
You can use git log [commit_range/dates/other_constraints] -- <filename(s)>
to show all changelogs pertaining to a specific file, and you can add contraints to the dates/commits/etc. 您可以使用
git log [commit_range/dates/other_constraints] -- <filename(s)>
来显示与特定文件相关的所有更改日志,并且可以向日期/提交/等添加约束。 as well. 同样。
Use git show <same stuff>
to actually show the files at each stage... 使用
git show <same stuff>
来实际显示每个阶段的文件......
git log file
shows the commit ids for all commits that affected file . git log file
显示影响文件的所有提交的提交ID。
git show commitid:file
prints the contents of the relevant version of the file to stdout. git show commitid:file
将相关文件版本的内容打印到stdout。
Note that in the git show
command, if you just specify the file name is relative to the root of your git repository unless you specify a path, not to your current directory. 请注意,在
git show
命令中,如果您只是指定文件名是相对于git存储库的根目录,除非您指定路径,而不是指定当前目录。 To show a file in the current directory: 要在当前目录中显示文件:
git show commitid:./file*
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.