Join old and new repo, created by copying files (not cloning), preserving commit history
To simplify things I have the following structure in git old_repo for
subpath/old_commit_1 subpath/old_commit_2 subpath/old_commit_latest
I decided to move to a new_repo and just copied the latest version of “subpath” (from old_commit_latest) into it without any commit history.
- Completely remove files from Git repo and remote on GitHub
- Hard reset to a previous git Commit - Not working
- git remote branch multiple elements reference
- How to update a git clone --mirror?
- How to view remote Git revision on Heroku
- “Proper” way to pull git “production branch” to production server
So the new_repo now has “subpath” and a bunch of new commits I made to it:
subpath/new_commit_subpath_added # added subpath here subpath/new_commit_1 subpath/new_commit_2 subpath/new_commit_latest
Now I need to migrate all the history from old_repo to the new_repo to get the following tree in new_repo:
subpath/old_commit_1 subpath/old_commit_2 subpath/old_commit_latest subpath/new_commit_1 subpath/new_commit_2 subpath/new_commit_latest
How do I do that?
I only need to do it to master branch, but I have lots of files there in the same situation. And subpath and filenames in old_repo matches the ones in new_repo.
I guess I need to create patches for subpaths in old_repo, rollback to the first commit for each subpath in the new_repo, remove that first commit, apply patches and then rebase all the new commits over it. Not sure how to do it all. Will appreciate some help.
One Solution collect form web for “Join old and new repo, created by copying files (not cloning), preserving commit history”
You should have both new and old versions available as valid repositories. The old version should better be on your local machine, new can be on local or remote (say, github).
It’s always a good idea to have backups of both repos and projects.
I assume that the last commit of old version is exactly the first commit of the new. If that’s not so:
- Reset the newer version to it’s first commit.
- Delete the files in older version project folder except .git, but including .gitignore and other git settings.
- Copy the files from newer to older version project folder.
- Save all changes as a new commit on old/master.
# go to the old repo folder cd path/to/old # add the new repo as a remote git add remote newrepo path/to/new/.git #check that it's properly added git remote show newrepo #fetch data from new git fetch newrepo #create a branch "new", tracking git checkout -b new newrepo/master #merge changes to the old master git checkout master git merge newrepo #an editor will open with a merge commit message. If you've done the preparations, there should be no merge conflicts. #this should show a complete history now git log --oneline
Now you have the joint history and latest commits in the old project directory.