简体   繁体   English

git - 从现有的创建新的回购,保留历史

[英]git - create new repo from existing one, keep history

I'm not sure how I should do that.我不确定我应该怎么做。 I read threads on stack but I don't want to break anything on the old (existing) repo so I think its better to ask...我阅读了堆栈上的线程,但我不想破坏旧的(现有的)回购协议中的任何内容,所以我认为最好问...

I want to create new repo from existing one, keep the history of the existing repo and of course keep the existing repo unchanged.我想从现有的回购创建新的回购,保留现有回购的历史,当然保持现有回购不变。 I just want my new repository to be a totally separate one but with the commits from the existing one.我只希望我的新存储库是一个完全独立的存储库,但包含来自现有存储库的提交。

How can I achieve that purely using git commands?我怎样才能纯粹使用 git 命令来实现?

Thanks.谢谢。

Simply clone the repository, change its origin and push to your own remote empty repository.只需克隆存储库,更改其来源并推送到您自己的远程空存储库。

git clone url/original/repo
cd repo

Track all remote branches as local ones :将所有远程分支作为本地分支进行跟踪:

for i in $(git for-each-ref --format=%(refname:short) \
  --no-merged=origin/HEAD refs/remotes/origin); do \
    git switch --track $i; \
done

(replace origin with upstream if you already had renamed origin as upstream ) (如果您已经将origin重命名为upstream ,请将origin替换为upstream

Finally:最后:

git remote rename origin upstream
git remote add origin url/new/repo
git push --mirror

暂无
暂无

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

相关问题 如何创建一个新的 Git 存储库而不是旧的存储库并保留提交历史? - How to create a new Git repo instead of an old one and keep the commits history? 从头开始为v2.0。我应该继续使用现有的git repo还是开始一个新的? - Starting from scratch for v2.0. Should I keep using the existing git repo or start a new one? 从已经存在的 repo 的子目录创建新的 git repo - Create new git repo from already existing repo's subdirectory 我需要将现有git仓库中的一些文件移动到新的。 我可以保留他们的历史吗? - I need to move some files from my existing git repo to a new one. Can I retain their history? git合并并保留原始回购记录中的历史记录 - git merge and keep history from original repo 如何将一个 repo 移动到另一个 repo 文件夹并保留 git 历史记录? - How to move one repo to another repo folder and keep git history? Visual Studio从现有的git repo创建新的解决方案 - Visual Studio create new solution from existing git repo Git:从现有项目创建一个新项目 - Git: create a new project from an existing one 在现有的Git仓库中创建一个新的Xcode项目 - Create a new Xcode project in an existing Git repo 如何从 git 现有存储库切换并初始化新存储库,因为我可以将项目的所有活动保存在同一个在线存储库中 - How do I switch from git existing repo and init new one as I can keep all activity of my project in a same online repo
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM