如何替换git存储库?

NAR*_*KOZ 19 git github repository

我创建了一个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.
Run Code Online (Sandbox Code Playgroud)

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

wup*_*tah 36

你只需要使用一点力量:

git push --force origin master

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

  • 如果想要保留以前的提交并且只是从新的repo添加新的东西作为另一个提交怎么办? (3认同)