- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我在一个 git blame 被有效破坏的仓库中。
我想在 git blame 中忽略两个提交。
现在每次我 git blame 一行时,我都会看到 [commit 2] 的作者而不是真正的逻辑作者。
我最终不得不执行 git log [有问题的文件]
,或者 this question 中列出的另一个解决方案.
每当我在 Intellij 中使用 Annotate 功能时,这两个提交让我很难过(这基本上是 git blame)。
有没有人在不重写历史的情况下解决过这个问题?
最佳答案
These two commits make me sad whenever I use the Annotate feature in IntelliJ (which is basically git blame).
Has anybody ever fixed this problem before without rewriting history?
2019年第三季度之前,没有。
但是在 Git 2.23 中,您将能够指示 git blame 忽略这两个有问题的提交。 (IntelliJ“注释”功能可能需要一段时间才能 catch )
git blame --ignore-rev
works on the assumption that the specified commit made an uninteresting change (e.g. reformatting).
Unfortunately both removing and adding a file are quite drastic changes so--ignore-rev
won't help here.
也就是说,git blame
现在可以忽略提交(甚至在这种特殊情况下可能不会)。
一般来说,从 Git 2.23 开始:
“git blame
”学会了“忽略”历史记录中的提交,其影响(以及它们的存在)被忽略。
你可以在你的 git config
中注册它!您甚至不需要在每次 git blame
调用时都在参数中传递这些提交。
参见 commit 78fafbb (2019 年 6 月 30 日),以及 commit 1d028dc (2019 年 6 月 20 日)作者 Michael Platings (``) .
参见 commit 07a54dc (2019 年 6 月 28 日)作者:Jeff King (peff
) .
参见 commit f0cbe74 , commit a07a977 (2019 年 6 月 20 日),和 commit 1fc7338 , commit 8934ac8 , commit ae3f36d , commit 55f808f , commit f93895f , commit 24eb33e (2019 年 5 月 15 日)Barret Rhoden (brho
) .
(由 Junio C Hamano -- gitster
-- merge 于 commit 209f075 ,2019 年 7 月 19 日)
blame
: add the ability to ignore commits and their changes
Commits that make formatting changes or function renames are often not interesting when blaming a file.
A user may deem such a commit as 'not interesting' and want to ignore and its changes it when assigning blame.For example, say a file has the following git history / rev-list:
---O---A---X---B---C---D---Y---E---F
Commits
X
andY
both touch a particular line, and the other commits do not:X: "Take a third parameter"
-MyFunc(1, 2);
+MyFunc(1, 2, 3);
Y: "Remove camelcase"
-MyFunc(1, 2, 3);
+my_func(1, 2, 3);
git-blame
will blameY
for the change.
I'd like to be able to ignoreY
: both the existence of the commit as well as any changes it made.
This differs from-S rev-list
, which specifies the list of commits to process for the blame.
We would still processY
, but just don't let the blame 'stick.'This patch adds the ability for users to ignore a revision with
--ignore-rev=rev
, which may be repeated.
They can specify a set of files of full object names of revs, e.g. SHA-1 hashes, one per line.
A single file may be specified with theblame.ignoreRevsFile
config optionor with--ignore-revs-file=file
.
Both the config option and the command line option may be repeated multiple times.An empty file name
""
will clear the list of revs from previously processed files.
Config options are processed before command line options.For a typical use case, projects will maintain the file containing revisions for commits that perform mass reformatting, and their users have the option to ignore all of the commits in that file.
Additionally, a user can use the
--ignore-rev
option for one-off investigation.
To go back to the example above,X
was a substantive change to the function, but not the change the user is interested in.
The user inspectedX
, but wanted to find the previous change to that line - perhaps a commit that introduced that function call.To make this work, we can't simply remove all ignored commits from the rev-list.
We need to diff the changes introduced byY
so that we can ignore them.
We let the blames get passed toY
, just like when processing normally.
WhenY
is the target, we make sure thatY
does not keep any blames.
Any changes thatY
is responsible for get passed to its parent. Note we make one pass through all of the scapegoats (parents) to attempt to pass blame normally; we don't know if we need to ignore the commit until we've checked all of the parents.The blame_entry will get passed up the tree until we find a commit that has a diff chunk that affects those lines.
One issue is that the ignored commit did make some change, and there is no general solution to finding the line in the parent commit that corresponds to a given line in the ignored commit.
That makes it hard to attribute a particular line within an ignored commit's diffcorrectly.For example, the parent of an ignored commit has this, say at line 11:
commit-a 11) #include "a.h"
commit-b 12) #include "b.h"Commit
X
, which we will ignore, swaps these lines:commit-X 11) #include "b.h"
commit-X 12) #include "a.h"We can pass that blame entry to the parent, but line 11 will be attributed to commit A, even though "include b.h" came from commit
B
.
The blame mechanism will be looking at the parent's view of the file at line number 11.
ignore_blame_entry()
is set up to allow alternative algorithms for guessing per-line blames.
Any line that is not attributed to the parent will continue to be blamed on the ignored commit as if that commit was not ignored.
Upcoming patches have the ability to detect these lines and mark them in the blame output.The existing algorithm is simple: blame each line on the corresponding line in the parent's diff chunk.
Any lines beyond that stay with the target.For example, the parent of an ignored commit has this, say at line 11:
commit-a 11) void new_func_1(void *x, void *y);
commit-b 12) void new_func_2(void *x, void *y);
commit-c 13) some_line_c
commit-d 14) some_line_dAfter a commit 'X', we have:
commit-X 11) void new_func_1(void *x,
commit-X 12) void *y);
commit-X 13) void new_func_2(void *x,
commit-X 14) void *y);
commit-c 15) some_line_c
commit-d 16) some_line_dCommit
X
nets two additionally lines: 13 and 14.
The currentguess_line_blames()
algorithm will not attribute these to the parent,whose diff chunk is only two lines - not four.When we ignore with the current algorithm, we get:
commit-a 11) void new_func_1(void *x,
commit-b 12) void *y);
commit-X 13) void new_func_2(void *x,
commit-X 14) void *y);
commit-c 15) some_line_c
commit-d 16) some_line_dNote that line 12 was blamed on
B
, thoughB
was the commit fornew_func_2()
, notnew_func_1()
.
Even whenguess_line_blames()
finds a line in the parent, it may still be incorrect.
--ignore-rev <rev>::
Ignore changes made by the revision when assigning blame, as if the change never happened.
Lines that were changed or added by an ignored commit will be blamed on the previous commit that changed that line or nearby lines.
This option may be specified multiple times to ignore more than one revision.--ignore-revs-file <file>:
Ignore revisions listed in
file
, which must be in the same format as anfsck.skipList
.
This option may be repeated, and these files will be processed after any files specified with theblame.ignoreRevsFile
config option.
An empty file name,""
, will clear the list of revs from previously processed files.
git config
new documentation :
blame.ignoreRevsFile:
Ignore revisions listed in the file, one unabbreviated object name per line, in
git blame
.
Whitespace and comments beginning with#
are ignored.
This option may be repeated multiple times.
Empty file names will reset the list of ignored revisions.
This option will be handled before the command line option--ignore-revs-file
.
由于线检测并不总是完美的:
blame
: add config options for the output of ignored or unblamable lines
When ignoring commits, the commit that is blamed might not be responsible for the change, due to the inaccuracy of our heuristic.
Users might want to know when a particular line has a potentially inaccurate blame.Furthermore,
guess_line_blames()
may fail to find any parent commit for a given line touched by an ignored commit.
Those 'unblamable' lines remain blamed on an ignored commit.
Users might want to know if a line is unblamable so that they do not spend time investigating a commit they know is uninteresting.This patch adds two config options to mark these two types of lines inthe output of blame.
The first option can identify ignored lines by specifying
blame.markIgnoredLines
.
When this option is set, each blame line that was blamed on a commit other than the ignored commit is marked with a '?
'.For example:
278b6158d6fdb (Barret Rhoden 2016-04-11 13:57:54 -0400 26)
appears as:
?278b6158d6fd (Barret Rhoden 2016-04-11 13:57:54 -0400 26)
where the '
?
' is placed before the commit, and the hash has one fewer characters.Sometimes we are unable to even guess at what ancestor commit touched aline.
These lines are 'unblamable.'
The second option,blame.markUnblamableLines
, will mark the line with '*
'.For example, say we ignore e5e8d36d04cbe, yet we are unable to blamethis line on another commit:
e5e8d36d04cbe (Barret Rhoden 2016-04-11 13:57:54 -0400 26)
appears as:
*e5e8d36d04cb (Barret Rhoden 2016-04-11 13:57:54 -0400 26)
When these config options are used together, every line touched by an ignored commit will be marked with either a '
?
' or a '*
'.
这意味着 git config
man page现在有:
blame.markUnblamables:
Mark lines that were changed by an ignored revision that we could not attribute to another commit with a '*' in the output of
git blame
.blame.markIgnoredLines:
Mark lines that were changed by an ignored revision that we attributed to another commit with a '
?
' in the output ofgit blame
.
最后,改进git blame
行检测:
blame
: add a fingerprint heuristic to match ignored lines
This algorithm will replace the heuristic used to identify lines from ignored commits with one that finds likely candidate lines in the parent's version of the file.
The actual replacement occurs in an upcoming commit.The old heuristic simply assigned lines in the target to the same line number (plus offset) in the parent. The new function uses a fingerprinting algorithm to detect similarity between lines.
The new heuristic is designed to accurately match changes made mechanically by formatting tools such as clang-format and clang-tidy.
These tools make changes such as breaking up lines to fit within a character limit or changing identifiers to fit with a naming convention.
The heuristic is not intended to match more extensive refactoring changes and may give misleading results in such cases.In most cases formatting tools preserve line ordering, so the heuristic is optimized for such cases. (Some types of changes do reorder lines e.g. sorting keep the line content identical, the
git blame -M
option can already be used to address this).
The reason that it is advantageous to rely on ordering is due to source code repeating the same character sequences often e.g. declaring an identifier on one line and using that identifier on several subsequent lines.
This means that lines can look very similar to each other which presents a problem when doing fuzzy matching. Relying on ordering gives us extra clues to point towards thetrue match.The heuristic operates on a single diff chunk change at a time.
It creates a “fingerprint” for each line on each side of the change.Fingerprints are described in detail in the comment for
struct fingerprint
, but essentially are a multiset of the character pairs in a line.
- The heuristic first identifies the line in the target entry whose fingerprint is most clearly matched to a line fingerprint in the parent entry.
Where fingerprints match identically, the position of the lines is used as a tie-break. - The heuristic locks in the best match, and subtracts the fingerprint of the line in the target entry from the fingerprint of the line in the parent entry to prevent other lines being matched on the same parts of that line.- It then repeats the process recursively on the section of the chunk before the match, and then the section of the chunk after the match.
Here's an example of the difference the fingerprinting makes.
Consider a file with two commits:commit-a 1) void func_1(void *x, void *y);
commit-b 2) void func_2(void *x, void *y);After a commit '
X
', we have:commit-X 1) void func_1(void *x,
commit-X 2) void *y);
commit-X 3) void func_2(void *x,
commit-X 4) void *y);When we blame-ignored with the old algorithm, we get:
commit-a 1) void func_1(void *x,
commit-b 2) void *y);
commit-X 3) void func_2(void *x,
commit-X 4) void *y);Where
commit-b
is blamed for 2 instead of 3.With the fingerprint algorithm, we get:
commit-a 1) void func_1(void *x,
commit-a 2) void *y);
commit-b 3) void func_2(void *x,
commit-b 4) void *y);Note line 2 could be matched with either
commit-a
orcommit-b
as it isequally similar to both lines, but is matched withcommit-a
because itsposition as a fraction of the new line range is more similar tocommit-a
as a fraction of the old line range.
Line 4 is also equally similar to both lines, but as it appears after line 3 which will be matched first it cannot be matched with an earlier line.For many more examples, see
t/t8014-blame-ignore-fuzzy.sh
which containsexample parent and target files and the line numbers in the parent thatmust be matched.
关于git - 我可以将 git blame 配置为始终忽略某些提交吗?想要一劳永逸地修复 git blame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34957237/
我正在使用 TFS 2018 在构建步骤中运行以下 powershell 命令。 Start-Job -ScriptBlock { Invoke-Command -FilePath \\MyS
我在这里读了很多问题,有人说需要设置 VOIP 模式,应用程序应该在重启后自行启动。但我的应用主要做基于背景位置的事情。我的应用程序不是基于 VOIP 的,但重启后必须重新启动它。有什么办法可以做到或
我在一个有 15 个子站点和 13 个不同架构页面的大项目中。当前,该站点基于 ui.route对于所有页面和我的数据集 $http Angular 要求。在搜索控制台上进行测试和试验后,谷歌似乎看不
我看过一千个帖子,其中有人在询问如何在 javascript 中检测互联网连接,并且总是有人说使用 navigator.onLine 而另一个人说它不可靠并且只告诉您连接是否可用,如果您已连接则不会。
我用 sys.path.append('D:/my_library_folder/') import mymodule 为了导入一些模块。 如何永久添加这个文件夹D:/my_library_folde
注意:这是一个超出 Asp.Net 领域的问题和网络应用程序。 一般来说,尤其是在库或控制台应用程序方面,为了触发并忘记异步方法,最好只调用异步方法而不用 await使用它或使用 Task.Run ?
学习 Scala 时,我学到的第一件事就是每个函数都会返回一些东西。不存在像 Java 中那样的“void”函数/方法。因此,从数学角度来说,许多 Scala 函数都是真正的函数,并且对象在很大程度上
我已经在这里看到类似的问题描述了同样的问题,人们给出了答案,甚至有人回复说它有帮助,但其中没有任何东西对我完全有用。 这是我的代码: File: Analy
假设我可以在两个域上设置 HTTP header ,有没有办法使用 CORS(来自另一个域)将图像绘制到 canvas 元素上并提取它的使用 IE9 和/或 IE10 的位图? 版本 11 之前的 I
我是一名优秀的程序员,十分优秀!