Home > OS >  Git log for the next change on a specific file line in a remote branch
Git log for the next change on a specific file line in a remote branch

Time:06-21

I'm exploring the git history of the project FFMpeg. I got the changes performed on each file between the commits 517573a67088b5c7a25c18373434e3448892ee93 and 80bb65fafab1d2f5f58a8453c6334c784ee27c08 by creating a patch with the command:

git diff 80bb65fafab1d2f5f58a8453c6334c784ee27c08..c5079bf3bccd24bf8ed45ff47ff4071fd09e9fd8 -p > my.patch

Now, for instance, I know that the file doc/examples/encode_video.c has been modified at row 149 and I would get the only the next commit after c5079bf3bccd24bf8ed45ff47ff4071fd09e9fd8 that modifies this line. Considering that some commits are on remotes, I'm using the command:

git log -L149,149: doc/examples/encode_video.c -1 c5079bf3bccd24bf8ed45ff47ff4071fd09e9fd8..HEAD --remotes

but git returns the message:

fatal: More than one commit to dig from: origin/HEAD and HEAD?

I think the problem is that I'm trying to log a commit on a remote, not on the master branch, but it's just a speculation. How can I solve it?

CodePudding user response:

The doc for the line log functionality (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. [...]

Notice that there is no space between the colon and the filename, so your command should be:

git log -L149,149:doc/examples/encode_video.c -1 c5079bf3bccd24bf8ed45ff47ff4071fd09e9fd8..HEAD --remotes

With this syntax I get the same error message as you. The doc states that the line-log functionality is limited to a revision walk starting from a single revision. Here you are giving a range (c5079bf3bccd24bf8ed45ff47ff4071fd09e9fd8..HEAD), as well as the --remotes arguments, whose docs says:

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

So you are not at all giving a single revision to git log, hence the error message.


Now to try to get the answer you are looking for. git log does not talk to the server, so if you do not have all commits locally (you are working in an old clone, for example), you should git fetch first, as joanis points out.

Then, you could start by looking at all the commits that touch the file you are interested in between c5079bf3bccd24bf8ed45ff47ff4071fd09e9fd and what the master branch was pointing to last time you fetched it :

$ git log --oneline c5079bf3bccd24bf8ed45ff47ff4071fd09e9fd8..origin/master  doc/examples/encode_video.c
1698cd8422 doc/examples/encode_video: add explanations in comments.

OK, there is a single commit touching that file. Let's take a look at its content:

$ git show 1698cd8422 | head -20
commit 1698cd8422c8a363e25dd94beb61c0a6d68bd67c
Author: Nicolas George <[email protected]>
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

OK, so the first hunk starts at line 155. So here is an answer to your query: there is no commit in the range c5079bf3bccd24bf8ed45ff47ff4071fd09e9fd8..origin/HEAD that touch line 149 in the file doc/examples/encode_video.c.

EDIT after experimenting a bit more, it seems the line log functionality does support being given a range. So this invocation would give you the same answer:

git log -L149,149:doc/examples/encode_video.c -1 c5079bf3bccd24bf8ed45ff47ff4071fd09e9fd8..origin/HEAD

The command returns nothing since as noted above no commits in that range modify line 149 in that file.

  • Related