문제

So in an ideal world, when I started this project, I would have cloned from a source, and then committed all my changes to this repo. When the main project was updated, I could pull those changes into my repo. (This is one way traffic, no pushing going on.)

However, when I started, I did not clone, but simply downloaded a released ZIP of the code, unzipped it, and then did a git init. I have since committed all my changes to this copy of the code. However, the main codebase has now been updated, but as my copy is not a merge, but my own repo of the same base code, I cannot merge the master's changes into mine.

Is there any way of getting these changes from the main code into my repo without having to start again?

도움이 되었습니까?

해결책

You can fix your repository by rebasing the changes of your private repository on top of the remote changes.

  • add a new remote to your repository containing the correct remote git URL.
  • fetch from that remote to fetch all the correct remote commits to your own repository
  • use git rebase to transplant you commits on top of the remote commits.
  • merge your branch into the remote one.

This would be something like:

cd $your_git_repository
git remote add origin $URL
git fetch origin
git branch -m my_branch
git rebase --onto $base_commit $your_first_commit my_branch
git merge $remote_branch
git log --graph --decorate --oneline

where $base_commit is the commit corresponding to the zip you downloaded in the first place, and $your_first_commit is the commit you commited the extracted zip file as.

다른 팁

Simplest way - clone the latest version of code into, say folderA. Say you were working in the unzipped source in folderB. Copy folderB contents into folderA. Commit the changes. Push!

You can also do, assuming you are on branch master:

git remote add origin
git pull --allow-unrelated-histories origin master

And then merge the two repos.

If you have more branches, use git merge with the same --allow-unrelated-histories flag

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top