如何替换Git代码库?

30

我创建了一个Git仓库并上传了一些东西。后来,我为这个项目创建了一个新目录,并为它初始化了一个新的Git。现在我想推送更改并替换仓库中的旧内容。当我运行git push origin master时,会得到以下结果:

! [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.

我该怎么办才能解决这个问题?


相关:https://dev59.com/B2oy5IYBdhLWcg3wkO-g - Ruben Bartelink
1个回答

52

您只需要使用一点力量:

git push --force origin master

--force 也可以缩写为 -f


4
如果想保留先前的提交记录,并只将来自新代码库的新内容作为另一个提交添加,应该怎么做? - Defozo
1
@Defozo,请查看这个答案 - Suragch

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接