0

We have a problem that our repository size exceeded the allowed limit and we are now blocked to push any local commit.

So we used bfg to remove big files and re-write the whole history of the repository then pushed it to a new one, in meanwhile multiple commits were produced by other developers.

I want to know a simple way to move the commits that we couldn't push into the new repository? as I don't want to apply each change manually.

Mahmoud Adam
  • 5,772
  • 5
  • 41
  • 62
  • Ideally, you would have asked your developers to refrain from making any commits during the time you were rewriting the history. You will need to rebase the unpushed commits onto your new history using `git rebase`, and then you can push them to the new remote repo. You will need to fetch/pull from the new repo first. Do not attempt to push the new commits as is, as that will push the old history with the large files. – David Sugar Jan 23 '20 at 14:23
  • but there were already some commits that were not be able to push from multiple developers. Unfortunately this happened at the middle of the week – Mahmoud Adam Jan 23 '20 at 14:37

3 Answers3

0

I want to know a simple way to move the commits that we couldn't push into the new repository? as I don't want to apply each change manually.

a commit always stores a reference to it's parent-commit. So each commit also stores the entire history of the project up until the very first commit. So when you "transplant" a commit into a new project, you also have to transplant the entire history with it.

You can achieve this (or at least something very close to it) by a simple git remote set-url followed by a force push on the branches you want to keep.

I think if you don't take the commit into the new reposity, but only the most recent trees instead, you would have some interesting possibilities, that wouldn't rely on copying the entire history.

I think the most straight-forward way to do this would be just to copy the most recent working tree into the new repo and check it in there.

wotanii
  • 2,470
  • 20
  • 38
0

I think I found a nice solution based on this question

I did the following:

  1. Add oldRepo remote pointing to old repository folder
git remote add oldRepo <oldRepoPath>/.git
git fetch oldRepo
  1. Repeat the following for each branch you want to migrate its commits
git checkout <yourBranch>
git cherry-pick <OldestUnpushedCommitSHA>..<LatestsUnpushedCommitSHA>
git push
  1. At the end remove oldRepo remote
git remote remove oldRepo
Mahmoud Adam
  • 5,772
  • 5
  • 41
  • 62
0

Here's an illustration of how to move the needed commits to the new repo. Perhaps if a developer is not a git expert, an expert should do this for him:

Original repo:

m1<-m2<-m3<-m4<--master

New repo:

m1a-m2a-m3a-m4a<--master
m1a-m4a have the large files removed

Developers Repo:

origin/master|
             V
m1<-m2<-m3<-m4<-a<-b<-c<--master
a,b,c need to be pushed to the new repo

Step 1: Add and fetch the new history from the new repo

git remote add newRepo <new repo url>
git fetch newRepo

Developers repo:

origin/master|
             V
m1<-m2<-m3<-m4<-a<-b<-c<--master<--head

m1a<-m2a<-m3A<m4a<--newRepo/master

Step 2: Create new local branch and cherry-pick or rebase the new commits to it:

git checkout -b newRepo_master newRepo/master 
git cherry-pick a b c

Developers repo:

origin/master|
             V
m1<-m2<-m3<-m4<-a<-b<-c<--master

  newRepo/master|
                V
m1a<-m2a<-m3A<m4a<-aa<-ba<-ca<--newRepo_master (local branch)<-head

Step 3: Push new commits to new repo on newRepo's master branch

git push --set-upstream newRepo master

Step 4: (Optional but recommended) Move local master branch

git checkout -B master newRepo_master
git branch -D newRepo_master (delete temporary local branch)

Developers repo:

origin/master|
             V
m1<-m2<-m3<-m4<-a<-b<-c

              newRepo/master|
                            V
m1a<-m2a<-m3A<m4a<-aa<-ba<-ca<--master

New repo:

    m1a-m2a-m3a-m4a<-aa<-ba<-ca<--master
David Sugar
  • 1,042
  • 6
  • 8