On Thu, Aug 12, 2021 at 12:42:17PM -0700, William wrote:

> I am trying to figure a way to find the newly added *strings* in the commit 
> diff,.
> 
> If I do a "git diff" I get all the changes which included newly added 
> strings, modified strings as-well made in the commit, I only want the newly 
> added strings(not files) in that commit,is there a way this can be achieved?

I doubt it's possible simply because the very question - which strings are new
as opposed to changed - is unanswerable in general; at least not without
specifying a very narrow (and, I think, quite arbitrary) set of restrictions
to do such classification.

The only workable solution I can think of is programming and then using -
via the "Git attributes" mechanism - a custom "diff driver" [1] which would
implement the algorythm for finding "newly added" strings.

One more thought, though.
You might try playing with a poor man's approach to detecting "newly added"
strings by searching through a stock diff Git generates by searching for
such blocks of text starting with the '+' character, which are not immediately
preceded by a line starting with the '-' character.  In other words,

  aaa
  bbb
 + ccc
 + ddd
  eee

can be considered to mean the lines "ccc" and "ddd" are "newly added", while

  aaa
  bbb
 - ccc
 + ddd
 + eee
  fff

can be considered to mean the lines "ddd" and "eee" are replacing the line
"ccc" - and are, hence, not "newly added".

Still, as you can see, the string "eee" in the last example can be considered
or not considered as newly added; that's what I was talking about in the
opening part of my answer.

 1. https://git-scm.com/docs/gitattributes#_defining_an_external_diff_driver

-- 
You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/git-users/20210815122957.6ug5clwts5xz4qiq%40carbon.

Reply via email to