如何替换git存储库? [英] How to replace a git repository?

查看:76
本文介绍了如何替换git存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个git存储库,并对其进行了一些更新.后来,我为此项目创建了一个新目录,并为其初始化了新的git.现在,我要推送更改并替换存储库中的旧内容.当我运行git push origin master时,我会得到

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 master I get

! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com: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.

该怎么办?

推荐答案

您只需要用一点力即可:

You just need to use a little force:

git push --force origin master

--force也可以缩写为-f.

这篇关于如何替换git存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆