git pull --rebase vs git rebase:有什么危险?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38017517/
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
git pull --rebase vs git rebase : what's the danger?
提问by sab
I don't understand the difference between git pull --rebase
and git rebase
, without any other options.
我不明白之间的差别git pull --rebase
,并git rebase
没有任何其他选择。
I don't understand if they are safe, a good practice, or very dangerous.
我不明白它们是安全的、好的做法还是非常危险的。
Can I break the historic of commit by doing a git pull --rebase
in local?
我可以通过git pull --rebase
在本地执行 a来打破 commit 的历史吗?
采纳答案by Luis
I don't recommend rebasing at all but just for private branches. By privateI mean branches that you're pretty sure only you have pulled.
我根本不建议 rebase,而只是针对私有分支。通过私人我的意思是分支,你敢肯定只有你已经退出。
A rebase changes the starting point of the branch to some newer commit, thus merging all the commits to that point. This could lead to merge conflicts to people that had in their repository the old branch base. I would recommend plain merge always and leave rebasing only for certain situations (feature branches, for example).
变基将分支的起点更改为某个较新的提交,从而将所有提交合并到该点。这可能会导致与在其存储库中拥有旧分支库的人发生合并冲突。我建议始终进行简单合并,并且仅在某些情况下(例如,功能分支)保留变基。
Regarding your question:
关于你的问题:
- git rebaserebases the branch you want.
- git pull --rebaseperforms a fetch + rebase in the branches you pull. Normally a pull would fetch + merge.
- git rebase 重新设置你想要的分支。
- git pull --rebase在您拉取的分支中执行 fetch + rebase。通常拉取+合并。
回答by everton
git pull --rebase
is a shorthand for git fetch
and then a plain git rebase
, as opposed as to the default git merge
. The practical difference is that applying only the latter would not fetchany new commits from your remote prior to rebasing your code on top of, as it would only take into account what your local repository's already aware of.
git pull --rebase
是 的简写git fetch
,然后是普通的git rebase
,而不是默认的git merge
。实际的区别在于,仅应用后者不会在将代码重新设置在其之上之前从远程获取任何新提交,因为它只会考虑本地存储库已经知道的内容。
It's also worth mentioning that merging conflicts would appear in the same way as a regular git pull.
还值得一提的是,合并冲突会以与常规 git pull 相同的方式出现。