使用我的存储库覆盖远程 git 存储库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6310208/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:33:49  来源:igfitidea点击:

Overriding remote git repository with my repository

git

提问by rid

The remote repository contains a bad version. I have the copy of a good version locally. I want to replace everything that's on the remote repository with my current repository (the remote repository has a few more commits (including a merge) that should not have happened).

远程存储库包含错误版本。我在本地有一个好的版本的副本。我想用我当前的存储库替换远程存储库上的所有内容(远程存储库还有一些不应该发生的提交(包括合并))。

If I try to push, it tells me I need to pull first, but I don't want to do that, because that would mess my local version. I want the remote repo to contain what I have locally.

如果我尝试推送,它会告诉我我需要先拉,但我不想这样做,因为那会弄乱我的本地版本。我希望远程仓库包含我在本地拥有的内容。

How can I do that?

我怎样才能做到这一点?

回答by David Fells

  1. Make a new local branch from your known good version
  2. Pull
  3. Switch to the known bad branch
  4. Fully merge your known good branch into the known bad branch
  5. Commit and push
  1. 从你已知的好版本创建一个新的本地分支
  2. 切换到已知的坏分支
  3. 将已知好的分支完全合并到已知的坏分支
  4. 提交和推送

I usually use a process like this to preserve exactly what changed, have an isolated branch that's a known good copy, etc. It's probably excessive compared to using --force, but I prefer it.

我通常使用这样的过程来准确保留更改的内容,拥有一个已知良好副本的独立分支等。与使用 --force 相比,这可能是过度的,但我更喜欢它。