[英]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.