What I understand is someone copied the files to a new repo and lost their history.
It should not have been necessary to copy the files to a new repo in the first place. The reorganization should have happened as a normal commit. Then tools such as git log
and git blame
would be able to continue to track the history of the files across renames and copies. The only reason I can think you would need a new repository is if the history got bloated with large files like videos, images, and office documents. That is better solved using git-lfs retroactively.
Now that you're in this situation, the best thing to do is to rewrite the new repository on top of the old one. Let's say your old and new repos look like this.
old
A - B - C - D [master]
origin
X - Y - Z [master]
local
X - Y - Z [origin/master]
[master]
"origin" is the new repository you cloned from. "local" is your clone.
You want to stitch them together like this.
old
A - B - C - D [master]
origin
A - B - C - D - X1 - Y1 - Z1 [master]
new
A - B - C - D - X1 - Y1 - Z1 [origin/master]
[master]
First, make the old repository a remote of the new one and fetch it.
$ cd new
$ git remote add old <url to old repo>
$ git fetch old
old
A - B - C - D [master]
origin
X - Y - Z [master]
local
A - B - C - D [old/master]
X - Y - Z [origin/master]
[master]
Now your new repository has the old history of master available as origin/master.
Then rebase the new commits on top of the old commits.
$ git checkout master
$ git rebase old/master
old
A - B - C - D [master]
origin
X - Y - Z [master]
local
A - B - C - D [old/master]
\
X1 - Y1 - Z1 [master]
X - Y - Z [origin/master]
Now it's time to push your changes. Your local master and remote master have "diverged", your local changes are no longer simply on top of the remote ones. You will need to force the push. Use git push --force-with-lease
to safely force the push.
$ git push --force-with-lease
old
A - B - C - D [master]
origin
A - B - C - D - X1 - Y1 - Z1 [master]
local
A - B - C - D [old/master]
\
X1 - Y1 - Z1 [origin/master]
[master]
Remove old as a remote.
$ git remote rm old
old
A - B - C - D [master]
origin
A - B - C - D - X1 - Y1 - Z1 [master]
local
A - B - C - D - X1 - Y1 - Z1 [origin/master]
[master]
Others who have cloned the new repository and done work should git pull --rebase
to update their master branch.