强制 Git 变基
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6876035/
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
Forcing a Git rebase
提问by FDS
Use case: Three git clones of the same repository A, B, B2. Repos A and B are normal, B2 is naked (made with --bare). All under my control, i.e. there is only one user.
用例:同一存储库 A、B、B2 的三个 git 克隆。Repos A 和 B 是正常的,B2 是裸的(用 --bare 制作)。一切都在我的控制之下,即只有一个用户。
On site B, I do work (several git commits), then git push B2.
在站点 B,我工作(几次 git 提交),然后 git push B2。
- On site A, git pull B2.
- On site A, git rebase -i xx..HEAD to squash some commits and clean history (a great command).
- Q: How to communicate the result to site B?
- 在站点 A 上,git pull B2。
- 在站点 A 上, git rebase -i xx..HEAD 压缩一些提交并清理历史记录(一个很好的命令)。
- 问:如何将结果传达给站点 B?
I can do:
我可以:
- git push --force B2
- git push --force B2
But this is not quite right. The site B working directory will have a strange history after a git pull B2.
但这并不完全正确。在 git pull B2 之后,站点 B 工作目录将有一个奇怪的历史记录。
I need some way to not use --force. I'd like to throw away xx..HEAD on B2, then push normally from A. Perhaps:
我需要一些不使用 --force 的方法。我想扔掉 B2 上的 xx..HEAD,然后从 A 正常推送。也许:
On B2 (the naked repo)
在 B2(裸回购)
- git reset --hard xx
- git reset --hard xx
Not sure that is enough. I can do it by re-cloning from site A (delete B2, git init --bare, push from A), but that seems like overkill. The How to push/pull Git rebasepost seems relevant, but I'm hoping for some answer besides "don't do this".
不确定这是否足够。我可以通过从站点 A 重新克隆来实现(删除 B2,git init --bare,从 A 推送),但这似乎有点矫枉过正。该如何推/拉的Git重订后似乎有关,但我希望除了“不这样做”的一些答案。
Bottom line, how do I truly and completely throw away commits on B2 so the rebased history from A will be accepted as new commits?
最重要的是,我如何真正彻底地丢弃 B2 上的提交,以便 A 的重新调整历史记录将被接受为新提交?
采纳答案by Karl Bielefeldt
I need some way to not use --force. I'd like to throw away xx..HEAD on B2, then push normally from A.
我需要一些不使用 --force 的方法。我想扔掉 B2 上的 xx..HEAD,然后从 A 正常推送。
Um, throwing away xx..HEAD on B2, then pushing normally from A is pretty much the exact definition of --force
. Just use --force
again when pulling to B and you'll be okay, as long as you rebase any branches in B back to commit xx or earlier before pulling.
嗯,扔掉 B2 上的 xx..HEAD,然后从 A 正常推动几乎是--force
. 只要--force
在拉到 B 时再次使用就可以了,只要在拉动之前将 B 中的任何分支变回提交 xx 或更早。
回答by nes1983
git reset --hard
throws away commits just in the sense in which you want them to be thrown away.
丢弃提交只是在您希望它们被丢弃的意义上。