【问题标题】:How to replace a git repository?如何替换 git 存储库?
【发布时间】:2010-09-24 16:56:44
【问题描述】:

我创建了一个 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.

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

【问题讨论】:

标签: git github repository


【解决方案1】:

你只需要用一点力:

git push --force origin master

--force也可以简写为-f

【讨论】:

  • 如果一个人想要保留以前的提交并且只是从新的 repo 中添加新的东西作为另一个提交呢?
  • @Defozo,见this answer
猜你喜欢
  • 2020-03-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-03
  • 1970-01-01
  • 2020-01-03
  • 2011-01-13
  • 1970-01-01
  • 2012-03-26
相关资源
最近更新 更多