Michael Michael - 1 year ago 52
Git Question

Matching unversioned sources against git repository

I have a legacy project, also containing sources for several open source libraries. Unfortunately, some of the libraries are simple snapshots without any revision information.
I am looking for a way to identify the matching commit in the libraries repositories (git-driven).

What I've been doing so far, is some kind of mental 'bisecting' changes of single files, but these files are moved often between commits and following turned out to be rather difficult.

Preconditions, that could be utilized:

  • an exact match exists

  • some heuristic time interval information is possibly applicable

  • the projects are not too big (<100kB C++ code)

Answer Source

Why don't you do the following:

  1. Clone the repository of the library

  2. Overwrite the working tree with the version you have at hand

  3. Run git diff against all commits:

    #!/usr/bin/env bash
    for rev in $(git rev-list --all)
        if git diff --exit-code $rev &> /dev/null
            echo $rev

Even if there is no exact match, this procedure can be easily enhanced to search for the revision with the least differences from your version.