问题描述:

I looked at Note about fast-forwards and know how a fast-forward updates a branch. But I want to know how non fast-forward updates a branch? Above doc says:

For example, suppose you and somebody else started at the same commit

X, and you built a history leading to commit B while the other person

built a history leading to commit A. The history looks like this:

 B

/

---X---A

If you did non fast-forward update, the changes introduced by commit A will be lost,

because everybody will now start building on top of B.

But losing changes introduced by A is not clear for me. Does a non fast-forward update overwrite destination branch completely and remove A from history? So history will looks like X -- B. Or it simply tries to do a merge? Or another changes will occur?

网友答案:

You have to take into account that the linked page is talking about git push, that is you are uploading your local branch into a remote server.

In this context, doing a fast-forward update is the usual thing: you just add commits to the tip of the remote branch. And oppositely, a non fast-forward update is a push that removes commits from the tip of the remote branch, before possibly adding more commits.

So answering your questions:

Does a non fast-forward update overwrite destination branch completely and remove A from history?

Yes, it will do exactly that. You force the remote branch to look exactly like your local one.

网友答案:

Yes, B would effectively replace A in the update if you did that push. Usually you'd try to rebase B on top of A before pushing.

相关阅读:
Top