2

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?

jub0bs
  • 60,866
  • 25
  • 183
  • 186
  • Are you interested in a single file or multiple files? When you write "how much of my code", what measure are you actually referring to? – jub0bs Apr 03 '18 at 12:56
  • Maybe `git blame` and `grep` for your name? Might help with some quick and dirty estimates. – Stephen Newell Apr 03 '18 at 13:03
  • @Jubobs interested in multiple files, although I can write a script to iterate over single files – Kirby Gaming Apr 03 '18 at 14:02
  • @StephenNewell good enough for me, care to submit that as an answer? – Kirby Gaming Apr 03 '18 at 14:03
  • While they can say they changed licence, if you still have the old copy of their code, you can still use it under their original licence, unless they were in violation, see [Open Source - Am I in danger if a project component is relicensed?](https://opensource.stackexchange.com/a/1611/3408) – Ferrybig Apr 03 '18 at 14:36
  • If you need to do this in GitHub - [check this](https://stackoverflow.com/a/49838096/820410) – Pankaj Singhal Oct 06 '20 at 16:56

1 Answers1

2

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.

Stephen Newell
  • 7,330
  • 1
  • 24
  • 28