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"
5
  • Related: stackoverflow.com/questions/1425892/… Commented Apr 8, 2014 at 18:55
  • This might work: stackoverflow.com/a/10548919/350351 Commented Apr 8, 2014 at 18:56
  • Did you git clone the second project from the first, or did you just add files from the last commit of the 1st project? Commented Apr 8, 2014 at 18:58
  • @Daenyth: thanks--I'll check those both out. Commented Apr 8, 2014 at 19:01
  • @Cupcake: I merely copied the files--did not clone. Commented Apr 8, 2014 at 19:02

1 Answer 1

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 
Sign up to request clarification or add additional context in comments.

5 Comments

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?
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 describes how you can automate merge process, but my advice is: try to resolve conflicts yourself.
I really appreciate your responses, but I think I haven't been clear enough in my question. I'll make it more explicit.
OK, my bad. Didn't catch that first project was abandoned. git merge -Xours master should do the trick. There should be no conflicts.
This did not work for me on a recent attempt, perhaps due to unrelated histories. Instead, git replace --graft worked, per this answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.