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

前端 未结 5 1131
暖寄归人
暖寄归人 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:55

    See the man page for git-log and gitdiffcore. I believe this command would do it, but it might not be quite right:

    git log -G "var identifier =" file.js
    

    EDIT: Here's a rough start for a bash script to show the actual lines. This might be more what you're looking for.

    for c in $(git log -G "something" --format=%H -- file.js); do
        git --no-pager grep -e "something" $c -- file.js
    done
    

    It uses git log -G to find the interesting commits, using --format=%H to produce a list of commit hashes. It then iterates over each interesting commit, asking git grep to show the lines from that commit and file that contain the regex, prefaced with the commit hash.


    EDIT: Changed to use -G instead of -S as suggested in comments.

提交回复
热议问题