git 如果我在推送后变基会发生什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39098811/
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
What happens if I rebase after pushing?
提问by Dunno
I always hear that it's something scary and something I should never do. For example, here's how the pull dialog looks like in SourceTree:
我总是听说这是可怕的事情,我永远不应该做的事情。例如,以下是 SourceTree 中拉取对话框的样子:
So I'm curious, what would happen and how bad would it be if I had pushed changes, then rebased and pushed them again? And how to fix the repository if I'd break it this way?
所以我很好奇,如果我推动更改,然后重新定位并再次推动它们,会发生什么以及会有多糟糕?如果我以这种方式破坏它,如何修复存储库?
回答by Mateusz
Nothing would happen, but your next push would be not accepted.
什么都不会发生,但您的下一次推送将不被接受。
Unless you would force push. This would not break remote repository also, so it is also not that bad.
除非你强行推动。这也不会破坏远程存储库,所以也没有那么糟糕。
Things go bad when you have more people using this repo. Rewriting history can cause a bit of chaos for others who will pull new changes from remote. Especially if they do not have good knowledge of git. There can be different things that might happen for person pulling rewritten remote branch depending on state of their local repository.
当你有更多的人使用这个 repo 时,事情就会变得很糟糕。重写历史可能会给其他人带来一些混乱,因为他们将从远程获取新的更改。特别是如果他们对 git 没有很好的了解。根据本地存储库的状态,拉动重写的远程分支的人可能会发生不同的事情。
So if someone would work on feature X and you changed the code on which he based his changes, he might get at least upset to downright angry depending on how much of his work you made obsolete.
因此,如果有人在功能 X 上工作,而您更改了他所做更改所依据的代码,那么他可能至少会生气到彻底生气,这取决于您使他的工作有多少过时。
回答by thelr
In the scenario you are listing in SourceTree, SourceTree rebases the local commits that haven't been pushed on top of the changes that you are pulling from the remote.
在您在 SourceTree 中列出的场景中,SourceTree 将尚未推送到您从远程拉取的更改之上的本地提交变基。
If you had already pushed changes before using THAT option, those changes wouldn't be rebased because they're already in the remote.
如果您在使用 THAT 选项之前已经推送了更改,那么这些更改将不会重新定位,因为它们已经在远程中。
The only exception may be if you have multiple remotes, and have pushed changes to one remote, then do a pull/rebase from another - that could cause serious problems.
唯一的例外可能是,如果您有多个遥控器,并将更改推送到一个遥控器,然后从另一个遥控器执行拉取/变基 - 这可能会导致严重问题。
Whether you should rebase or not during a pull is a subject of debate. I'm not recommending it, but it is generally safe. https://developer.atlassian.com/blog/2014/12/pull-request-merge-strategies-the-great-debate/
在 pull 期间是否应该变基是一个有争议的话题。我不推荐它,但它通常是安全的。https://developer.atlassian.com/blog/2014/12/pull-request-merge-strategies-the-great-debate/