Reputation: 67
Background: A project I once worked on changed its licensing, and I want to know how much of my code is still in the final product.
How can I take an old commit ID and compare the changes made in that commit with the current code in any branches latest commit?
EX: I add some code
int b = j+k;
updateRefs(b,k);
and later this code gets changed to
int b = j+m;
updateRefs(b,k);
How can I see how much of my code (ex the updateRefs(b,k);
) is still left in the latest commit of a branch?
Upvotes: 2
Views: 119
Reputation: 7863
It'll be rough around the edges, but you can use git blame
and pipe that through grep
. For example, running on one of my projects (limiting to 10 lines since I'm the only contributor):
$ git blame CMakeLists.txt | grep Stephen | head -n 10
^72094b3 (Stephen Newell 2018-04-02 19:49:20 -0600 1) cmake_minimum_required(VERSION 3.9)
^72094b3 (Stephen Newell 2018-04-02 19:49:20 -0600 2) cmake_policy(VERSION 3.9)
^72094b3 (Stephen Newell 2018-04-02 19:49:20 -0600 3)
^72094b3 (Stephen Newell 2018-04-02 19:49:20 -0600 4) project("houseguest"
^72094b3 (Stephen Newell 2018-04-02 19:49:20 -0600 5) LANGUAGES
^72094b3 (Stephen Newell 2018-04-02 19:49:20 -0600 6) CXX
^72094b3 (Stephen Newell 2018-04-02 19:49:20 -0600 7) VERSION
^72094b3 (Stephen Newell 2018-04-02 19:49:20 -0600 8) 0.1.0
^72094b3 (Stephen Newell 2018-04-02 19:49:20 -0600 9) )
^72094b3 (Stephen Newell 2018-04-02 19:49:20 -0600 10)
This will show whoever last touched the line, so it'll miss some cases (e.g., whitespace change or comments added to the line). Should give you at least a rough estimate though.
Upvotes: 2