4

I have a section of code in an old version of software that has been removed from the current version. I want to find when this section was removed from the code base. Currently my way of doing this is to manually diff my integration branch against each of the old commits, but there are far to many commits between the version of the file that has the code, and my current version.

So in short, if I ahve code on lines 44-52 of a file in an old version, that does not exist in the new version how can I find the commit when it was removed?

jrahme
  • 253
  • 1
  • 12

2 Answers2

7

Try git log -S"<code>" -- <file path(s)>, it shows commits in which occurrence of specified string changes.

That means if u remove a code piece, then the reference to that code will decrease by 1.

e.g

git log -S"hello world" -- src/

This shows commits in which "hello world" is added or removed.

Stunner
  • 12,025
  • 12
  • 86
  • 145
Eric
  • 22,183
  • 20
  • 145
  • 196
1

The way to do what you want is to use the bisect run <script>.
Use the bisect as you did so far and use the bisect with the script option.

The script will return the appropriate code for skipping (or 125 for not testable - much more suitable in your case).

Note that the script should exit with code 0 if the current source code is good, and exit with a code between 1 and 127 (inclusive), except 125, if the current source code is bad.

Any other exit code will abort the bisect process. It should be noted that a program that terminates via "exit(-1)" leaves $? = 255, (see the exit(3) manual page), as the value is chopped with "& 0377".

The special exit code 125 should be used when the current source code cannot be tested. If the script exits with this code, the current revision will be skipped (see git bisect skip above).

125 was chosen as the highest sensible value to use for this purpose, because 126 and 127 are used by POSIX shells to signal specific error status (127 is for command not found, 126 is for command found but not executable---these details do not matter, as they are normal errors in the script, as far as bisect run is concerned).


Demo code

Here you can view a sample code on how to use git bisect

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167