【问题标题】:How to push an existing local repo into a newly remote one without loosing git history如何在不丢失 git 历史记录的情况下将现有的本地 repo 推送到新的远程 repo
【发布时间】:2019-04-30 12:18:30
【问题描述】:

我有一个本地 git repo 有一些历史。
我想将它添加到我的远程 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


【解决方案1】:

我想你已经在本地正确管理你的 repo(git add、commit 等),所以这可能不起作用,因为在源(你的服务器)上还没有分支 master,因为它是裸露的,你还没有'最初没有从服务器克隆 repo。

你应该试试

git push -u origin master

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

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

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

【讨论】:

    猜你喜欢
    • 2020-10-23
    • 2022-06-14
    • 2022-11-24
    • 1970-01-01
    • 2018-04-25
    • 1970-01-01
    • 2022-01-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多