Ron Ziroby Romero
Ron Ziroby Romero

Reputation: 9449

How do I reconnect history when copying git projects?

I have a Git project that was copied from another git project. It was just a file copy and commit, so it didn't copy history. I've since imported the commits from the previous files, but they aren't connected to the new versions of the file. So if I look for the history of a file that exists in both repos, history only goes to the time I copied the project across.

I tried checking out the last revision of the old project, and git merging the first revision of the new project. Then I merged to master. This makes the project's git history look right, but each individual's file history is unchanged.

It's almost like we want to delete the revision that says "create all these files" and instead prepend the old project's history.

Is this possible with Git?

Upvotes: 1

Views: 224

Answers (2)

janos
janos

Reputation: 124646

It seems to me that you can rebuild the history with a fairly straightforward cherry-pick:

  1. Given remotes old and new pointing to the old and new repos respectively
  2. Create a new branch from old/master, which is at the last revision of the old repo
  3. git cherry-pick first..new/master where first is the SHA1 of the first commit in the new repo (you can find it with git log new/master and press G to jump to the end)

The result will be basically the commits in the old repo + the commits in the new repo without first. As usual with a cherry-pick, commit dates and authors will be preserved.

Upvotes: 1

VonC
VonC

Reputation: 1324278

prepend the old project's history. Is this possible with Git?

That should be possible, following this answer.

It uses git grafts described in git repository layout, but that old answer could benefit from the more recent git replace command.
See "Collating repositories or grafting earlier history with Git"

Upvotes: 2

Related Questions