0

Let us call original source State A.

I committed State B through State F into Repo 1. State B represents modified version of state A. I made the mistake of not committing state A through B in Repo 1.

In Repo 2, I added copy of original source, in State A. I then made changes to look like State B (not literally State B as in Repo 1, but something similar to it). I then manually made changes to State B to look like State F (not literally State F as in Repo 1, but something similar to it) in Repo 1. Then I made more changes from State F to State Current.

I would like to merge Repo 1 and Repo 2 into a single logical historical timeline. I do not want any of current files in Repo 2, which represents an older state, to be in current state of Repo 1.

What is the easiest way to do this? Any advice?

pyrrhic
  • 1,769
  • 2
  • 15
  • 27
  • See (1) [git: how to insert a commit as the first, shifting all the others?](http://stackoverflow.com/questions/645450/git-how-to-insert-a-commit-as-the-first-shifting-all-the-others), (2) [Git: how to add commits before first/initial/root commit?](http://stackoverflow.com/questions/16762160/git-how-to-add-commits-before-first-initial-root-commit), and (3) [How to add retro commits to a git repository?](http://stackoverflow.com/questions/18176144/how-to-add-retro-commits-to-a-git-repository). –  Aug 12 '13 at 01:23

1 Answers1

1

Sounds like you'll want to add state A as the root of your first repo. You can find instructions for doing so in the following:

  1. git: how to insert a commit as the first, shifting all the others?.
  2. Git: how to add commits before first/initial/root commit?.
  3. How to add retro commits to a git repository?.

You basically want to add state A to the first repo in an orphan branch, then use rebase with the --root and --onto flags to move the old history on top of A.

Option 2

Instead of making an orphan branch with state A, another option would just be to hard reset repo 2 to state A, add repo 1 as a remote, fetch repo 1's history, then rebase repo 1s history onto state A:

# In repo 2
git reset --hard A
git add remote repo1 <path-or-url-to-repo1>
git fetch repo1
git checkout <branch-with-state-A>
git rebase --onto A --root repo1/<remote-branch-with-B-through-F>
Community
  • 1
  • 1