如何替换 git 存储库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3789298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 09:09:19  来源:igfitidea点击:

How to replace a git repository?

gitgithubrepository

提问by NARKOZ

I created a git repository and updated it with some stuff. Later I created a new directory for this project and initialized new git for it. Now I want to push changes and replace the old contents in the repository. When I run git push origin masterI get

我创建了一个 git 存储库并用一些东西更新了它。后来我为这个项目创建了一个新目录并为它初始化了新的 git。现在我想推送更改并替换存储库中的旧内容。当我跑步时,git push origin master我得到

! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to '[email protected]:Username/repo2.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'Note about
fast-forwards' section of 'git push --help' for details.

What can I do to solve this?

我能做些什么来解决这个问题?

回答by wuputah

You just need to use a little force:

你只需要用一点力:

git push --force origin master

git push --force origin master

--forcecan also be abbreviated to -f.

--force也可以简写为-f