使用git在文件的特定行上查找令牌的第一个介绍 [英] Using git to find first introduction of token on a specific line of a file

查看:143
本文介绍了使用git在文件的特定行上查找令牌的第一个介绍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个文件A.cpp,并且我注意到文件的第15行有一个错误。假设这个错误是一个函数的const,它返回一个指向成员变量的指针,这意味着在函数上使用const在技术上是正确的,但是在语义上是错误的。我想与作出改变的作者讨论语义。

使用git,有没有办法找出哪个修订引入了const标记?更具体地说,我想知道谁引入了令牌。



git blame显示谁对该行进行了最后一次更改,但我实际上希望查找第一次提交包含令牌。

解决方案

git bisect 是你正在寻找的。使用这个命令,你可以很快找到提交什么提交const。



你用 git bisect start 开始这个过程,然后用git bisect good 标记一个没有const的旧版本,并将当前版本标记为 bisect bad 。然后系统会将您发送到中间的版本。你可以检查邪恶常量是否存在,并根据它来标记该版本的好坏。然后重复该过程,直到找到错误的提交。


Let's say I have a file A.cpp, and I notice an error on line 15 of the file. Let's say the error is a "const" on a function that returns a pointer to a member variable, meaning using const on the function is technically correct but semantically wrong. I would like to discuss the semantics with the author who made the change.

Using git, is there a way to find out which revision introduced the "const" token? More specifically, I'd like to know who introduced the token.

"git blame" shows who made the last change to the line, but I would actually like to find the first commit containing the token.

解决方案

git bisect is what you are looking for. With this command you can find quickly what commit introduced the const.

You start the process with git bisect start, then mark an old version without the const as good with git bisect good and and the current one as bisect bad. Then the system will send you to a version in the middle. You can check if the evil const is there, and mark that version good or bad depending on it. Then The process is repeated until you find the bad commit.

这篇关于使用git在文件的特定行上查找令牌的第一个介绍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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