简体   繁体   English

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

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

I have a local git repo with some history. 我有一些历史的本地git回购。
I would like to add it to my remote git server: 我想将其添加到我的远程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

If I clone the remote repo first, then copy the source code, I will lose the git history. 如果我先克隆远程仓库,然后复制源代码,我将丢失git历史记录。
Anyone knows how to do it ? 有人知道该怎么做吗?

I suppose you already manage correctly your repo locally (git add, commit and so on), so this probably doesn't work because on origin (your server) there is no branch master yet, as it is bare and you haven't cloned the repo from the server originally. 我想您已经在本地正确管理了您的仓库(git add,commit等),所以这可能不起作用,因为在源(您的服务器)上还没有分支母版,因为它是裸机并且您尚未克隆最初来自服务器的仓库。

You should try 你应该试试

git push -u origin master

It should push and create the remote master branch as well 它也应该推送并创建远程主分支

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

For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull[1] and other commands. 对于每个最新的或成功推送的分支,添加上游(跟踪)引用,该引用由无参数git-pull [1]和其他命令使用。 For more information, see branch..merge in git-config[1]. 有关更多信息,请参见git-config [1]中的branch..merge。

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

相关问题 如何将本地 git 存储库推送到远程 git 服务器? - How does one push a local git repo to a remote git server? 将本地新的Git存储库作为分支推送到现有的远程存储库? - Push local new Git repo to existing remote repo as branch? 如何在保持历史记录的同时将git repo推送到现有的SVN repo? - How to push a git repo to an existing SVN repo while maintaining history? 如何将本地git repo推送到远程分支? - How to push local git repo to remote branch? GIT 将一个仓库与另一个仓库中的文件夹合并,而不会丢失历史记录 - GIT MERGE a repo with a folder in another repo without loosing history 如何将本地Git仓库推送到新创建的Google Code项目? - How to push local Git repo to newly created Google Code project? Git如何通过远程仓库/本地仓库推送和拉动? - How does Git push and pull work with a remote repo/local repo? 如何在不更改远程文件的情况下更新远程 git 回购历史记录 - How to update remote git repo history without altering remote files Git“强制推送”从新的本地仓库到远程,但保持远程提交历史记录 - Git “force push” from new local repo to remote, but keeping remote commit history 仅将 git 推送到远程(Github)最后一次提交,没有历史记录? - Push git to remote (Github) only one last commit, without history?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM