Skip to content

Instantly share code, notes, and snippets.

@hainh
Last active April 15, 2021 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hainh/6a00dedea885bdcfb680fabddfe73d68 to your computer and use it in GitHub Desktop.
Save hainh/6a00dedea885bdcfb680fabddfe73d68 to your computer and use it in GitHub Desktop.

Repo 1: started from 1/1/2016 to 1/1/2020.

Repo 2: copied from last commit of repo 1 and continues till now

###Concatenating repo 2 to tail of repo 1:

From repo 2, add remote to repo 1:

git remote add old file://to/repo1/
git fet old

Checkout from old repo 1:

git checkout old/master old

Checkout from master (just to make a backup if you do something wrong):

git checkout master work-in-progress

Now I will replay commits from old repo 1 to current working branch (work-in-progress or wip same as master):

git rebase old -i

After this command, git will open a text editor list all commits of new repo 2 that we want to be tailed to repo 1's commit history. Actually it will replay commits of current branch wip to the tail of old and place all history to wip. You should check the list and "drop" unwanted commits (edit "pick" to "drop") such as first commit to repo 2 because this commit just added files to the repo. Now you would encounter some conflict: CONFLICT (content): Merge conflict in file/that/conflicted. Resolve conflict by content of newer commits. I did that by using TortoiseGIT on Windows by selecting resolving use the left file.

Continue rebasing:

git rebase --continue

Repeat doing resolving and rebasing till all commits are replayed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment