简体   繁体   中英

Git: Do commits on local, merged branch get pushed to remote?

Assume I have the following git history

          L1 - L2 - L3  <- Local branch
         /            \
A - B - C -- D -- E -- M <- master

where L1, L2, and L3 are commits on my local branch and M is the merge commit into master.

Now, when I push my changes to remote, will the commits in the local branch be part of the history or not? In other words, will the history in the remote repository look like the graph above or just like

A - B - C - D - E - M <- master

Also: What happens in the case of fast-forward merges?

A merge commit has two parent commits. You cannot just cut out the commits of the local branch from the history. M cannot exist without L3, L3 cannot exist without L2, and so on. This integrity is a fundamental to Git. So the pushed master branch will necessarily "look like a graph", the commits on the local branch won't vanish into thin air.

In a fast-forward merge, nothing special happens. The history is linear. It's not really a merge, it's really "just fast-forward". In your example, suppose there are no commits D and E, you merge the local branch, then the history becomes:

A - B - C - L1 - L2 - L3 <- master

Notice that there is no M either (no merge commit).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM