I had one Git repository (A) which contains the development of a project until a certain point. Then I lost the USB stick this repo A was on. Luckily I had a backup of the latest commit, so I could create a new repository (B) later where I imported the latest project’s state and continue development.
Now I recovered that lost USB stick, so I have two Git repositories.
I think I just have to rebase repo B onto repo A somehow, but I have no idea how to do that, maybe using fetch/pull and rebase?
If A and B are not the same repo (you created B by using the latest working copy you had), you have to use a graft to pretend that they have common history.
Let’s assume you’ve added A as a remote for B as per VonC’s answer, and the repo looks like this1:
Create a graft telling the root of B that its parent is the head of A:
Now the two histories above will appear as one when you request the history for B. Making the graft permanent is a simple
git filter-branchwith no arguments. After the filter-branch, though, you aren’t on any branch, so you shouldgit branch -D master; git checkout -b master.1
git tnylog=git log --oneline --graph --decorate