Git 责备——先前的提交?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5098256/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git blame -- prior commits?
提问by Sedate Alien
Is it possible to see who edited a specific line beforethe commit reported by git blame
, like a history of commits for a given line?
是否有可能在由 报告的提交之前查看谁编辑了特定行git blame
,例如给定行的提交历史?
For example, I run the following (on the superb uncrustify
project):
例如,我运行以下(在极好的uncrustify
项目上):
$ git blame -L10,+1 src/options.cpp
^fe25b6d (Ben Gardner 2009-10-17 13:13:55 -0500 10) #include "prototypes.h"
How can I find out who edited that line beforecommit fe25b6d
? And who edited it before thatcommit?
如何在提交之前找出谁编辑了该行fe25b6d
?又是谁之前编辑它是承诺?
采纳答案by Amber
git blame -L 10,+1 fe25b6d^ -- src/options.cpp
You can specify a revision for git blame to look back starting from (instead of the default of HEAD
); fe25b6d^
is the parent of fe25b6d
.
您可以为 git blame 指定一个修订以从(而不是默认的HEAD
)开始回顾;fe25b6d^
是 的父级fe25b6d
。
回答by Navneet
You can use git log -Lto view the evolution of a range of lines.
您可以使用git log -L查看一系列行的演变。
For example :
例如 :
git log -L 15,23:filename.txt
means "trace the evolution of lines 15 to 23 in the file named filename.txt".
意思是“跟踪名为 filename.txt 的文件中第 15 到 23 行的演变”。
回答by ThorSummoner
Amber's answer is correct but I found it unclear; The syntax is:
Amber 的回答是正确的,但我发现不清楚;语法是:
git blame {commit_id} -- {path/to/file}
Note: the --
is used to separate the tree-ish sha1 from the relative file paths. 1
注意:--
用于将树形 sha1 与相对文件路径分开。1
For example:
例如:
git blame master -- index.html
Full credit to Amberfor knowing all the things! :)
完全归功于琥珀知道所有事情!:)
回答by Holger B?hnke
You might want to check out:
你可能想看看:
git gui blame <filename>
Gives you a nice graphical display of changes like "git blame" but with clickable links per line, to move into earlier commits. Hover over the links to get a popup with commit details. Not my credits... found it here:
为您提供一个很好的图形显示更改,例如“gitblame”,但每行都有可点击的链接,以便进入更早的提交。将鼠标悬停在链接上以获取包含提交详细信息的弹出窗口。不是我的学分...在这里找到它:
http://zsoltfabok.com/blog/2012/02/git-blame-line-history/
http://zsoltfabok.com/blog/2012/02/git-blame-line-history/
git gui
is a graphical Tcl/Tc interface to git. Without any other params it starts a pretty simple but useful graphical app for committing files, hunks or even single lines and other similar commands like amend, revert, push... It's part of the git stock suite. On windows it is included in the installer. On debian - I don't know about other *nix systems - it has to be installed separately:
git gui
是 git 的图形化 Tcl/Tc 界面。没有任何其他参数,它会启动一个非常简单但有用的图形应用程序,用于提交文件、大块甚至单行和其他类似命令,如修改、还原、推送......它是 git stock 套件的一部分。在 Windows 上,它包含在安装程序中。在 debian 上 - 我不知道其他 *nix 系统 - 它必须单独安装:
apt-get install git-gui
From the docs:
从文档:
https://git-scm.com/docs/git-gui
https://git-scm.com/docs/git-gui
DESCRIPTION
A Tcl/Tk based graphical user interface to Git. git gui focuses on allowing users to make changes to their repository by making new commits, amending existing ones, creating branches, performing local merges, and fetching/pushing to remote repositories.
Unlike gitk, git gui focuses on commit generation and single file annotation and does not show project history. It does however supply menu actions to start a gitk session from within git gui.
git gui is known to work on all popular UNIX systems, Mac OS X, and Windows (under both Cygwin and MSYS). To the extent possible OS specific user interface guidelines are followed, making git gui a fairly native interface for users.
COMMANDS
blame
Start a blame viewer on the specified file on the given version (or working directory if not specified).
browser
Start a tree browser showing all files in the specified commit. Files selected through the browser are opened in the blame viewer.
citool
Start git gui and arrange to make exactly one commit before exiting and returning to the shell. The interface is limited to only commit actions, slightly reducing the application's startup time and simplifying the menubar.
version
Display the currently running version of git gui.
描述
基于 Tcl/Tk 的 Git 图形用户界面。git gui 专注于允许用户通过进行新提交、修改现有提交、创建分支、执行本地合并以及获取/推送到远程存储库来更改其存储库。
与 gitk 不同,git gui 专注于提交生成和单文件注释,不显示项目历史。然而,它确实提供了从 git gui 中启动 gitk 会话的菜单操作。
众所周知,git gui 适用于所有流行的 UNIX 系统、Mac OS X 和 Windows(在 Cygwin 和 MSYS 下)。尽可能遵循操作系统特定的用户界面指南,使 git gui 成为用户相当原生的界面。
命令
责备
在给定版本(或工作目录,如果未指定)上的指定文件上启动指责查看器。
浏览器
启动树浏览器,显示指定提交中的所有文件。通过浏览器选择的文件在blame 查看器中打开。
城市工具
启动 git gui 并安排在退出和返回 shell 之前进行一次提交。该界面仅限于提交操作,稍微减少了应用程序的启动时间并简化了菜单栏。
版本
显示当前运行的 git gui 版本。
回答by Will Sheppard
Building on the previous answer, this bash one-liner should give you what you're looking for. It displays the git blame history for a particular line of a particular file, through the last 5 revisions:
在上一个答案的基础上,这个 bash one-liner 应该给你你正在寻找的东西。它显示特定文件的特定行的 git blame 历史记录,通过最近 5 次修订:
LINE=10 FILE=src/options.cpp REVS=5; for commit in $(git rev-list -n $REVS HEAD $FILE); do git blame -n -L$LINE,+1 $commit -- $FILE; done
In the output of this command, you might see the content of the line change, or the line number displayed might even change, for a particular commit.
在此命令的输出中,您可能会看到特定提交的行更改内容,或者显示的行号甚至可能更改。
This often indicates that the line was added for the first time, after that particular commit. It could also indicate the line was moved from another part of the file.
这通常表明该行是在该特定提交之后第一次添加的。它还可能表明该行是从文件的另一部分移出的。
回答by Thomas W
There's also recursive-blame
. It can be installed with
还有recursive-blame
。它可以安装
npm install -g recursive-blame
回答by Mannu
回答by warvariuc
If you are using JetBrains Idea IDE (and derivatives) you can select several lines, right click for the context menu, then Git -> Show history for selection. You will see list of commits which were affecting the selected lines:
如果您使用的是 JetBrains Idea IDE(和衍生产品),您可以选择多行,右键单击上下文菜单,然后选择 Git -> 显示历史记录。您将看到影响所选行的提交列表:
回答by Michael Platings
As of Git 2.23 you can use git blame --ignore-rev
从 Git 2.23 开始,您可以使用git blame --ignore-rev
For the example given in the question this would be:
对于问题中给出的示例,这将是:
git blame -L10,+1 src/options.cpp --ignore-rev fe25b6d
(however it's a trick question because fe25b6d is the file's first revision!)
(然而这是一个棘手的问题,因为 fe25b6d 是文件的第一次修订!)
回答by Bill Chan
Building on DavidN's answer and I want to follow renamed file:
基于 DavidN 的回答,我想遵循重命名的文件:
LINE=8 FILE=Info.plist; for commit in $(git log --format='%h%%' --name-only --follow -- $FILE | xargs echo | perl -pe 's/\%\s/,/g'); do hash=$(echo $commit | cut -f1 -d ','); fileMayRenamed=$(echo $commit | cut -f2 -d ','); git blame -n -L$LINE,+1 $hash -- $fileMayRenamed; done | sed '$!N; /^\(.*\)\n$/!P; D'