I’ve got a) a working directory without the .git directory and b) a repository. a is some revision in the middle of the history of b.
How can I find out, which revision a matches in b?
I thought of a shellscript doing a diff from the working directory to all revisions and pick the one with the least (hopefully 0) differences.
That would be a bit raw (and I’m not sure how to do it), is there an easier way?
You could write a script to run
diff gitdir workdir | wc -cfor each commit. Then you could collate the results and say the commit which has the smallest difference (as measured bywc -c) is the closest commit to the bare working dir.Here is what it might look like in Python:
find_closest_sha1.py:
Example: