Git:在整个git历史记录中,显示指定文件中对单个行的所有更改 [英] Git: Show all of the various changes to a single line in a specified file over the entire git history

查看:130
本文介绍了Git:在整个git历史记录中,显示指定文件中对单个行的所有更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个(javascript)文件(比如说/ lib / client) .js),其中我有一个赋予变量的唯一标识符,如下所示:
var identifier =SOME_IDENTIFIER;



您可以将标识符想象为版本号:定期地,我们会将此变量更改为新的标识符。



我会喜欢做的是找到我们曾经使用过的所有唯一标识符。我怎么能用git来做到这一点?



我想可能有办法搜索git历史记录,并打印出符合var标识符=。我可以手动取消这个列表。



无论如何,我会很感激这里的任何见解。感谢。

解决方案

因为git 1.8.4 ,有一种更直接的方式来回答你的问题。



假设行 110 var identifier =SOME_IDENTIFIER; ,然后执行此操作:

  git log -L110,110:/lib/client.js 

这会返回触及该行代码的所有提交。



[ Git文档(请参阅-L命令行参数)]

I've looked around, and am not sure if this is possible, but here goes:

I have a (javascript) file (say /lib/client.js) in which I have a unique identifier assigned to a variable, like so: var identifier = "SOME_IDENTIFIER";

You can think of the identifier like a version number: Periodically, we'll change this variable to a new identifier.

What I'd like to do is find all of the unique identifiers we've ever used. How can I do this with git?

I imagine there might be a way to search through the git history, and print the line matching "var identifier =". I could de-dupe this list manually.

Anyway, I'd appreciate any insight here. Thanks.

解决方案

Since git 1.8.4, there is a more direct way to answer your question.

Assuming that line 110 is the line saying var identifier = "SOME_IDENTIFIER";, then do this:

git log -L110,110:/lib/client.js

This will return every commit which touched that line of code.

[Git Documentation (see the "-L" command line paramenter)]

这篇关于Git:在整个git历史记录中,显示指定文件中对单个行的所有更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆