I am learning git
and want to know how to get the exact line number of a modified line using git show commit_id
. I am writing a python
script to achieve some task and want the exact line number of modified line. For example consider the following:
//some extra lines here...
diff --combined describe.c
index fabadb8,cc95eb0..4866510
--- a/describe.c
+++ b/describe.c
@@@ -98,20 -98,12 +98,20 @@@
return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
}
- static void describe(char *arg)
-static void describe(struct commit *cmit, int last_one)
++static void describe(char *arg, int last_one)
{
+ unsigned char sha1[20];
+ struct commit *cmit;
struct commit_list *list;
static int initialized = 0;
struct commit_name *n;
+ if (get_sha1(arg, sha1) < 0)
+ usage(describe_usage);
+ cmit = lookup_commit_reference(sha1);
+ if (!cmit)
+ usage(describe_usage);
+
if (!initialized) {
initialized = 1;
for_each_ref(get_name);
In this output, at line 5
from top, gives 98
, but this not the line number where we made changes. How can we get the exact line number of modified line. One option is we scan the file and find the line line number by using the content of git show commit_id
output, but it's not efficient.