3

I have a rather unique situation:

  • I have a repository called Project1 that I worked on for a few months.
  • A year later, I created the repository Project1_Again that took off where Project1 left off.
  • Now, I would like the revision history to be continuous, so I would like them merged together, as if that new repository had never been created.

Is this possible?

To clarify:

Repo: Project1

  • rev1: main.cpp has contents "h"
  • rev2: main.cpp has contents "hello"
  • rev3: main.cpp has contents "hello world"

Repo: Project1_Again

  • rev1: main.cpp has contents "hello world"
  • rev2: main.cpp has contents "hello world again"

My goal is to get Project1's revision history into Project1_Again:

Repo: Project1_Again

  • rev1: main.cpp has contents "h"
  • rev2: main.cpp has contents "hello"
  • rev3: main.cpp has contents "hello world"
  • rev4: main.cpp has contents "hello world again"
user2588666
  • 821
  • 1
  • 7
  • 16

1 Answers1

2

For project1 chronologically before project2:

cd project1
git checkout --orphan merging_project2
git rm -rf .
git pull protocol://project2_address/ master
git merge -Xours master
Maciej Chałapuk
  • 454
  • 3
  • 11
  • 2
    Thank you. But this doesn't seem to completely work, as when I merge, it states that I have merge conflicts. I wouldn't expect merge conflicts, as the changes from project2 (in your example) should have all come before project1, and thus shouldn't conflict. Am I just missing something? – user2588666 Apr 08 '14 at 19:23
  • If you have the same files in both projects you will have conflicts, even if they have the same content. It's the situation when you have added a file on a branch and then (chronologically later) a file of the same name on second branch. Git concludes that you are adding a file that already exists. [This post](http://stackoverflow.com/questions/14182259/how-to-automatically-resolve-a-git-conflict-by-taking-the-version-in-the-current) describes how you can automate merge process, but my advice is: try to resolve conflicts yourself. – Maciej Chałapuk Apr 08 '14 at 19:32
  • I really appreciate your responses, but I think I haven't been clear enough in my question. I'll make it more explicit. – user2588666 Apr 08 '14 at 19:45
  • 2
    OK, my bad. Didn't catch that first project was abandoned. `git merge -Xours master` should do the trick. There should be no conflicts. – Maciej Chałapuk Apr 08 '14 at 19:54
  • This did not work for me on a recent attempt, perhaps due to unrelated histories. Instead, `git replace --graft` worked, per [this answer](https://stackoverflow.com/a/49779160/82216). –  Apr 11 '18 at 15:55