简体   繁体   English

如何将 git 存储库(包括所有分支)覆盖到另一个 git 存储库

[英]How to overwrite a git repository(including all branches) to another git repository

I have two git repos: orginal (with master and some feature branches) and new (having just the master branch as it is created new).我有两个 git 存储库:原始(带有主分支和一些功能分支)和的(只有主分支,因为它是新创建的)。 I want to copy everything from original (all the branches and history) to new .我想将所有内容从原始(所有分支和历史记录)复制到新的.

I have followed this resource and so far am able to copy all the branches except the master branch to the new repo.我已经关注了这个资源,到目前为止,我能够将除 master 分支之外的所有分支复制到的 repo。 This could happen since master exists for both the repos.这可能会发生,因为两个 repos 都存在 master。 Is there a way to overwrite the master branch from another repository?有没有办法从另一个存储库覆盖主分支?

You are looking for the git branch command.您正在寻找git branch命令。 Run this on the new repo after you fetched all branches from the original:从原始仓库获取所有分支后,在新仓库上运行此代码:

git branch --force master original/master

This forces the local master branch to point to the same commit as the remote master branch.这会强制本地 master 分支指向与远程 master 分支相同的提交。 (This assumes your remote is named original .) (这假设您的遥控器被命名为original 。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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