0

I need to find the "most probable" ancestor of a branch in Git.

Say: I had a repository with a develop branch that evolved. At one time in the past (I don't know when exactly), a clone was made and a copy was taken out. The .git/ folder was deleted and a new repository started and pushed to a different server.

Today also this second repository has evolved.

How can I find that specific common ancestor on the "first" server and to add, starting there, as a new branch, the master branch of my second repository?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
DDS
  • 2,340
  • 16
  • 34
  • 1
    If the initial content of the new repository was **exactly** the same as a commit on the old one, then you should be able to find a tree with the same id. Note that *any* change in file content (as well as missing files) will mess this up. Alternatively if there were only minor changes, you can try looking for sub-tree ids from the initial commit: any sub-tree (recursively) that contains the exact same content will produce a tree object with the same id. Finding those should lead you towards finding the "most similar" commit. – Joachim Sauer May 16 '23 at 09:19
  • No, it wasn't or, at least, I don't know because I didn'd do that. – DDS May 16 '23 at 09:44

2 Answers2

0

I think you need to do a manual search.

Add your files to a new local branch starting from HEAD.
Then write a script, to do a git diff [branch] [commit] working your way back through develop to before you think the implicit branch occurred.
Eg: git log -30 --pretty=format:%h to get a list of usable hashes.

Using --shortstat or --compact-summary should yield you results you may be able to find something in.
If it's a lot of commits you may need to parse some data, that's beyond me.

Jeroen3
  • 919
  • 5
  • 20
0

How can I find that specific common ancestor on the "first" server?

It's not so simple to do. Why?

  • You cloned a repository
  • Deleted the .git folder

Result: the file system (content) of a given point in time, which is not related to the Git content.


How can we figure out what is the ancestor based upon source?

  • It can be long process....

Few options

  1. In the first repository, add all files.
  2. Grab a few files (SHA-1)
  3. Using git bisect, search for those files in the second repository
  4. Once you find a match, use git log to search in which commits the file is included.

At this point, you have a list of files in the first repository, found the files in the second repository and based upon the match, you can "traverse" back in time to find out the maximum files match, and you should be able to find your commits.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
CodeWizard
  • 128,036
  • 21
  • 144
  • 167