使用我的存储库覆盖远程 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
Overriding remote git repository with my repository
提问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 Amber
Use the --force
, Luke.
使用--force
,卢克。
http://www.kernel.org/pub/software/scm/git/docs/git-push.html
http://www.kernel.org/pub/software/scm/git/docs/git-push.html
回答by David Fells
- Make a new local branch from your known good version
- Pull
- Switch to the known bad branch
- Fully merge your known good branch into the known bad branch
- Commit and push
- 从你已知的好版本创建一个新的本地分支
- 拉
- 切换到已知的坏分支
- 将已知好的分支完全合并到已知的坏分支
- 提交和推送
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 相比,这可能是过度的,但我更喜欢它。