git git中的强制推送和正常推送有什么区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43567577/
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 is the different between force push and normal push in git
提问by Sajith Herath
I want to know what is the different between force push and normal push and at what kind of situations i should do force push in git?Is it a good practice to do force push into master branch?
我想知道强制推送和普通推送有什么区别,在什么样的情况下我应该在 git 中强制推送?强制推送到 master 分支是一个好习惯吗?
采纳答案by VonC
You only force a push when you need to replace the remote history by your local history.
只有在需要用本地历史替换远程历史时才强制推送。
This happens when you rewrite the local history, typically through a git rebase
.
For instance, if you just pushed an incorrect commit, and amend it locally, using a push --force
can help correct a recentpush
当您重写本地历史时会发生这种情况,通常是通过git rebase
.
例如,如果你只是推送了一个不正确的提交,并在本地修改它,使用 apush --force
可以帮助纠正最近的推送
If you are the only one working on the branch you are force pushing, this is not a big deal.
If you are notthe only one, then you need to communicate clearly in order for other users to reset their own local branch to the new remote. Or you need to avoid force pushing in the first place.
如果你是唯一一个在你强制推送的分支上工作的人,这没什么大不了的。
如果您不是唯一一个,那么您需要清晰地沟通,以便其他用户将他们自己的本地分支重置为新的远程。或者您首先需要避免强行推动。
Is it a good practice to do force push into master branch?
强制推送到主分支是一个好习惯吗?
Generally, it is not a good practice (again unless you are the only one using the remote repo).
And don't forget that once a branch has been force pushed... you cannot know whodid the push --force
.
通常,这不是一个好习惯(同样,除非您是唯一使用远程存储库的人)。
并且不要忘记,一旦一个分支被强制推送......你不知道是谁做了push --force
.
回答by A H M Forhadul Islam
Force-pushing is a highly threatening and risky method if you're working in a common repository. Using this force pushing you should be able to force your local revision to the remote repository.
如果您在公共存储库中工作,强制推送是一种极具威胁性和风险的方法。使用这种强制推送,您应该能够将本地修订强制执行到远程存储库。
But forcefully pushing to remote repo is not a good practice. You can use normal push and solve the conflicts between commits if there are any.
但是强行推送到远程仓库并不是一个好习惯。您可以使用普通推送并解决提交之间的冲突(如果有)。