سؤال

I have the following problem: In a huge repository, there is a class that I'm interested in but that is no longer in the repository to be found. I stumbled over it in an earlier state after some search, and now I want to trace this class forward to the present.

Usually one would use Git log to trace the history of a file backward (to check who has modified that class), but since this class was deleted or moved, I would like to find the commit, where this class was removed or moved (especially to find the commit that states the reason WHY is was removed). Therefore I would need a mechanism to trace the history of that file into the "future".

To visualise this, I created a simple graphic that shows a series of commits (bubbles) :

Log-History to demonstrate forward tracking of an object in Git

  • Red bubbles are commits that don't contain that class
  • Green bubbles are commits that contain the class (at a certain point in time (1.1), the object was added and stayed in the code-base for a while)
  • The blue bubble (4) is the commit, where the class was removed (and the one I am interested in, because it might contain the reason, why it was removed, or where it was moved to)
  • The green bubble with the yellow border is the commit, where I found the class.

Now in a visual manner: I want the green line UP to the blue (1.2 -> 3 -> 4), whereas when I checkout state 1.2 and call log, I only get 1.2 -> 1.1.

هل كانت مفيدة؟

المحلول

There's no easy way to trace into the future, but you can search through history to find where it vanished.

If you have a path for the file, Git: How to search for a deleted file in the project commit history? shows how to locate the commit:

git log -- path/to/file

This will show all commits touching that file. You can then examine the first commit listed to see if it's a deletion or a move.

If the file's name is distinctive, and you believe it may have been renamed:

git log --name-only

You can search through these results for the filename.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top