gpt4 book ai didi

远程分支中特定文件行的下一次更改的 Git 日志

转载 作者:行者123 更新时间:2023-12-04 22:54:11 27 4
gpt4 key购买 nike

我正在探索项目的 git 历史 FFMpeg .我在提交之间对每个文件执行了更改 517573a67088b5c7a25c18373434e3448892ee9380bb65fafab1d2f5f58a8453c6334c784ee27c08通过使用以下命令创建补丁:

git diff 80bb65fafab1d2f5f58a8453c6334c784ee27c08..c5079bf3bccd24bf8ed45ff47ff4071fd09e9fd8 -p > my.patch
现在,例如,我知道文件 doc/examples/encode_video.c已在第 149 行修改我会得到 c5079bf3bccd24bf8ed45ff47ff4071fd09e9fd8 之后的唯一下一次提交修改这条线。考虑到一些提交是在 Remote 上,我正在使用以下命令:
git log -L149,149: doc/examples/encode_video.c -1 c5079bf3bccd24bf8ed45ff47ff4071fd09e9fd8..HEAD --remotes
但 git 返回消息:
fatal: More than one commit to dig from: origin/HEAD and HEAD?
我认为问题在于我试图在远程而不是主分支上记录提交,但这只是一种猜测。我该如何解决?

最佳答案

行日志功能的文档 ( git log -L ) says :

-L<start>,<end>:<file>
-L:<funcname>:<file>

Trace the evolution of the line range given by <start>,<end>, or by the function name regex <funcname>, within the <file>. You may not give any pathspec limiters. This is currently limited to a walk starting from a single revision, i.e., you may only give zero or one positive revision arguments, and <start> and <end> (or <funcname>) must exist in the starting revision. [...]


请注意,冒号和文件名之间没有空格,因此您的命令应该是:
git log -L149,149:doc/examples/encode_video.c -1 c5079bf3bccd24bf8ed45ff47ff4071fd09e9fd8..HEAD --remotes
使用此语法,我会收到与您相同的错误消息。该文档指出,行日志功能仅限于从单个修订开始的修订遍历。在这里,您给出了一个范围( c5079bf3bccd24bf8ed45ff47ff4071fd09e9fd8..HEAD ),以及 --remotes参数,其文档说:

Pretend as if all the refs in refs/remotes are listed on the command line as <commit>.


因此,您根本不会对 git log 进行一次修订。 ,因此出现错误消息。

现在尝试获得您正在寻找的答案。 git log不与服务器对话,因此如果您没有本地所有提交(例如,您正在使用旧克隆),您应该 git fetch首先,正如 joanis 指出的那样。
然后,您可以先查看在 c5079bf3bccd24bf8ed45ff47ff4071fd09e9fd 之间触及您感兴趣的文件的所有提交。以及您上次获取主分支时指向的内容:
$ git log --oneline c5079bf3bccd24bf8ed45ff47ff4071fd09e9fd8..origin/master  doc/examples/encode_video.c
1698cd8422 doc/examples/encode_video: add explanations in comments.
好的,有一个提交触及该文件。我们来看看它的内容:
$ git show 1698cd8422 | head -20
commit 1698cd8422c8a363e25dd94beb61c0a6d68bd67c
Author: Nicolas George <george@nsup.org>
Date: Mon Aug 16 15:05:59 2021 +0200

doc/examples/encode_video: add explanations in comments.

diff --git a/doc/examples/encode_video.c b/doc/examples/encode_video.c
index 908eb203d5..939ed68324 100644
--- a/doc/examples/encode_video.c
+++ b/doc/examples/encode_video.c
@@ -155,12 +155,25 @@ int main(int argc, char **argv)
for (i = 0; i < 25; i++) {
fflush(stdout);

- /* make sure the frame data is writable */
+ /* Make sure the frame data is writable.
+ On the first round, the frame is fresh from av_frame_get_buffer()
+ and therefore we know it is writable.
+ But on the next rounds, encode() will have called
+ avcodec_send_frame(), and the codec may have kept a reference to
好的,所以第一个大块从第 155 行开始。所以这是您查询的答案: c5079bf3bccd24bf8ed45ff47ff4071fd09e9fd8..origin/HEAD 范围内没有提交触及文件 doc/examples/encode_video.c中的第149行.
编辑 在尝试了更多之后,似乎行日志功能确实支持给定一个范围。所以这个调用会给你同样的答案:
git log -L149,149:doc/examples/encode_video.c -1 c5079bf3bccd24bf8ed45ff47ff4071fd09e9fd8..origin/HEAD
该命令不返回任何内容,因为如上所述,该范围内没有提交修改该文件中的第 149 行。

关于远程分支中特定文件行的下一次更改的 Git 日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72687312/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com