1

I made some commit A some time ago, which added a few new classes. Later on, a coworker reworked things with commit B, and deleted my classes.

In order to do some debugging, I am simply interested in looking at some of the deleted classes (to confirm that they contain some functionality that is basically missing now).

Are there (simple) ways to do that (assuming that git is used, and intellij)?

Edit: I figured by now that intellij has a context menu entry show all affected files in the version control window (for each commit listed there).

But I am wondering if there is a solution that works for cases, when I only remember the file name at hand. Getting to the files from a known commit is helpful, but what if identifying the commit is hard?

GhostCat
  • 137,827
  • 25
  • 176
  • 248

2 Answers2

1

You can use git bisect to find out when the file was deleted.

Here is a full demo on how to do it.
https://github.com/nirgeier/Tutorials-bisect

git bisect lets you search all the commits using binary search and you will be able to figure out when the desired code was removed.

The way to do what you want is to use the git 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
  • Looks nice, but doesn't work for me, as I can't simply include "stuff" from github in my work environment. Still worth a +1 ;-) – GhostCat Jan 10 '18 at 14:55
1

In the "Version Control" panel, there is a "Log" tab, here you could find any commit and see all added/changed/deleted files for the commit.

And if you don't know in which commit the file is deleted, just follow other questions, such as Find when a file was deleted in Git

kan
  • 28,279
  • 7
  • 71
  • 101
  • I was going to add that myself - yes that works. But the problem is of course - I do need to identify a commit first that contains that class. Pretty easy in this case, but maybe much harder in a few months. – GhostCat Jan 10 '18 at 14:56