什么是 git 快进?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29673869/
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 git fast-forwarding?
提问by adrianvlupu
This may sound like a dumb question but I can't find a simple answer to it.
这听起来像是一个愚蠢的问题,但我找不到一个简单的答案。
Is it ok to assume that fast-forward means all commits are replayed on the target branch and the HEAD
is set to the last commit on that branch?
可以假设快进意味着所有提交都在目标分支上重放并且HEAD
设置为该分支上的最后一次提交吗?
采纳答案by Abimaran Kugathasan
When you try to merge one commit with a commit that can be reached by following the first commit's history, Git simplifies things by moving the pointer forward because there is no divergent work to merge together – this is called a “fast-forward.”
当您尝试将一个提交与可以通过跟踪第一个提交的历史记录到达的提交合并时,Git 通过向前移动指针来简化事情,因为没有要合并的不同工作 - 这称为“快进”。
For more : http://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging
更多信息:http: //git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging
In another way,
用另一种方式,
If Master has not diverged, instead of creating a new commit, git will just point master to the latest commit of the feature branch. This is a “fast forward.” There won't be any "merge commit" in fast-forwarding merge.
如果 Master 没有发散,git 不会创建新的提交,而是将 master 指向功能分支的最新提交。这是一个“快进”。快进合并中不会有任何“合并提交”。
回答by Kaz
In Git, to "fast forward" means to update the HEAD
pointer in such a way that its new value is a direct descendant of the prior value. In other words, the prior value is a parent, or grandparent, or grandgrandparent, ...
在 Git 中,“快进”意味着以HEAD
这样一种方式更新指针,使其新值是先前值的直接后代。换句话说,先验值是父母,或祖父母,或祖父母,...
Fast forwarding is not possible when the new HEAD
is in a diverged state relative to the stream you want to integrate. For instance, you are on master
and have local commits, and git fetch
has brought new upstream commits into origin/master
. The branch now diverges from its upstream and cannot be fast forwarded: your master
HEAD
commit is not an ancestor of origin/master
HEAD
. To simply reset master
to the value of origin/master
would discard your local commits. The situation requires a rebase or merge.
当新数据HEAD
相对于您要集成的流处于发散状态时,无法进行快进。例如,您在master
本地提交并git fetch
已将新的上游提交带入origin/master
. 分支现在与其上游分叉并且不能快进:您的master
HEAD
提交不是origin/master
HEAD
. 简单地重置master
为 的值origin/master
将丢弃您的本地提交。这种情况需要变基或合并。
If your local master
has no changes, then it can be fast-forwarded: simply updated to point to the same commit as the latestorigin/master
. Usually, no special steps are needed to do fast-forwarding; it is done by merge
or rebase
in the situation when there are no local commits.
如果您的本地master
没有更改,那么它可以快速转发:只需更新以指向与最新的相同的提交origin/master
。通常,进行快进不需要特殊步骤;它是由merge
或rebase
在没有本地提交的情况下完成的。
Is it ok to assume that fast-forward means all commits are replayed on the target branch and the HEAD is set to the last commit on that branch?
可以假设快进意味着所有提交都在目标分支上重放并且 HEAD 设置为该分支上的最后一次提交吗?
No, that is called rebasing, of which fast-forwarding is a special case when there are no commits to be replayed (and the target branch has new commits, and the history of the target branch has not been rewritten, so that all the commits on the target branch have the current one as their ancestor.)
不,这就是所谓的rebase,其中快进是一种特殊情况,当没有提交被重放时(并且目标分支有新的提交,并且目标分支的历史没有被重写,所以所有的提交在目标分支上将当前分支作为其祖先。)