Git: Show all of the various changes to a single line in a specified file over the entire git history

前端 未结 5 1094
暖寄归人
暖寄归人 2020-12-22 23:30

I\'ve looked around, and am not sure if this is possible, but here goes:

I have a (javascript) file (say /lib/client.js) in which I have a unique identifier assigned

5条回答
  •  無奈伤痛
    2020-12-22 23:54

    If you adapt @rob's answer just a bit, git log will basically do this for you, if all you need is a visual comparison:

    git log -U0 -S "var identifier =" path/to/file
    

    -U0 means output in patch mode (-p), and show zero lines of context around the patch.

    You can even do this across branches:

    git log -U0 -S "var identifier =" branchname1 branchname2 -- path/to/file
    

    There may be a way to suppress the diff header, but I don't know of one.

提交回复
热议问题