简体   繁体   中英

How to change a fresh git repository into a branch from another repo?

I downloaded a 3rd party project as non-tracked files (without .git folder) and started a new git repository with $git init in it, to track my changes.

I later found out that this project already has a public git repository, which has the same state as the bare files I downloaded (is identical to my initial commit).

What I should have done:

Cloned the remote repo and made a new local branch and then pushed it to remote.

What I actually did:

Just took the files and started a clean local git repo (master) in it and made several commits.

What I want to do:

Turn my local initial commit into a branch of the remote repo (change its parent) and keep the changes I've already done.

I guess this should be possible, but I don't know enough Git.

Thanks!

Well, you could try the following (you may want to use a different name than origin , up to you):

  1. git remote add origin url_of_project_repository
  2. git fetch origin
  3. git rebase FETCH_HEAD

You have significant chances git will actually figure ot your base and the new remote's are actually the same set of files, and will resolve the fake merge conflict by skipping anything but your changes.

If that doesn't work peroperly, you could also juts clone the "real" repository somewhere else, then re-apply your changes on top of it (and there would be countless ways of doing this, from a very manual DIY way to some more automated means).

您可以将您的仓库作为远程添加到原始仓库,获取提交,并尝试重新绑定。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM