Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

merge git projects without common commit

Tags:

git

right now i have several projects tracked with git. Now, i want to make one big project, with several subfolders for each of the previous projects and preserve their history along with the history of the big project.

So basically what i have now is

projecta/
projectb/
projectc/
bigproject/

And what i want is

bigproject/
    projecta/
    projectb/
    projectc/

Is that even possible without losing history?

Cheers

like image 280
noobsaibot Avatar asked Jul 12 '26 23:07

noobsaibot


1 Answers

You could try:

#Preparing the repos: moving files in subdirectories
cd projecta
mkdir projecta
git mv file1 file2 dir1 dir2 projecta 
git commit -am "Moved file"
#Do it for each other repos

#Actually merging
git clone url_to_projecta bigproject
cd bigproject
git remote add b url_to_projectb
git remote add c url_to_projectc
git fetch --all
git merge b/master
git merge c/master

In plain English: You can merge Git trees even if they have nothing in common, so you just have to:

  • go in one of your repos
  • fetch the others (you now have several trees with no commits in common)
  • create merge-commits, to merge those trees

That's it.

And if you want to have a filesystem which looks like:

bigproject/
  projecta/
  projectb/
  projectc/

the easiest is to deal with it first

like image 160
gturri Avatar answered Jul 15 '26 13:07

gturri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!