【问题标题】:How to clear a GIT Repository如何清除 GIT 存储库
【发布时间】:2011-08-06 10:48:14
【问题描述】:

在 Tortoise SVN 中有一个Repo-Browser,我们可以简单地删除所有文件并再次添加新文件。

我们如何在 GIT 中做到这一点?

repo 未托管在 GITHub 中,并且除了 repo url 之外没有接口

为什么?

我创建了一个本地repo并推送到远程主机,但后来意识到在错误的目录中,所以,在本地很容易,只是

git init 
git add .
git commit -m "New place commit;"

git remote add alias https://user@domain.com/reponame.git
git push alias master

但我得到了错误

To https://user@domain.com/reponame.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'user@domain.com/reponame.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

Witch 很好,因为我正在推送一个新的仓库……所以我只想清除远程仓库以便能够推送这个新仓库……

【问题讨论】:

  • 可能你应该看到这个帖子:[how-do-i-remove-sensitive-files-from-gits-history][1] [1]: stackoverflow.com/questions/872565/…
  • 不完全一样,我要全部清除,从头开始,他不会。

标签: git msysgit


【解决方案1】:

我认为您正在寻找-f 标志:

git push -f alias master

它将强制远程存储库覆盖master 分支。

【讨论】:

  • 太棒了!标志太多了,我完全迷路了:)
【解决方案2】:

只需删除存储库顶层的.git 目录即可。然后,在同一个目录中:

git init
git add .
git commit -am 'Initial commit'

【讨论】:

    猜你喜欢
    • 2017-05-24
    • 1970-01-01
    • 2015-04-19
    • 2011-03-23
    • 2019-05-13
    • 1970-01-01
    • 2015-11-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多