繁体   English   中英

如何在不丢失git历史记录的情况下将现有本地存储库推送到新的远程存储库

[英]How to push an existing local repo into a newly remote one without loosing git history

我有一些历史的本地git回购。
我想将其添加到我的远程git服务器中:

# On my server, I create a remote repo
git init project.git --bare --shared

# On my local computer, I add the remote repo
git remote add origin user@server:/srv/git/projet.git

# Try to push
git push origin master
# error: src refspec master does not match any.
# error: failed to push some refs to 'user@server:/srv/git/projet.git'

# Try to pull
git pull origin master
# fatal: Couldn't find remote ref master
# fatal: the remote end hung up unexpectedly

如果我先克隆远程仓库,然后复制源代码,我将丢失git历史记录。
有人知道该怎么做吗?

我想您已经在本地正确管理了您的仓库(git add,commit等),所以这可能不起作用,因为在源(您的服务器)上还没有分支母版,因为它是裸机并且您尚未克隆最初来自服务器的仓库。

你应该试试

git push -u origin master

它也应该推送并创建远程主分支

从文档https://git-scm.com/docs/git-push#git-push--u

对于每个最新的或成功推送的分支,添加上游(跟踪)引用,该引用由无参数git-pull [1]和其他命令使用。 有关更多信息,请参见git-config [1]中的branch..merge。

暂无
暂无

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

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