I need to include some code previously not under version control into a git repository already containing some commits.
What I want to automate is the finding of a suitable "parent" commit which the new code will be a child commit of.
After some testing I think git diff-tree
will work best (since only one folder contains the relevant code for the testing of "parentship").
My approach is like this:
- loop through all existing commits and node sha1 of commit and sha1 of relevant subtree
- copy new files to repository, add them to the index
- note sha1 of relevant subtree in the index
- compare the existing relevant subtrees with the new candidate and calculate "similarity" by using git diff-tree of something similar
- choose the most similar existing subtree and make it's commit the parent of the new commit, i.e. check out the new parent (or
checkout --orphan
if not suitable parent can be found), empty working directory and fill with the new files and commit.
What's missing is a way to calculate the similarity! Maybe someone can give me a hint which combination of flags will help...
The code looks almost like PASCAL if that's important.