简体   繁体   English

Git:是否将本地合并分支上的提交推送到远程?

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

Assume I have the following git history假设我有以下 git 历史

          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.其中 L1、L2 和 L3 是我本地分支上的提交,M 是到 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. M没有L3就不能存在,L3没有L2就不能存在,依此类推。 This integrity is a fundamental to Git.这种完整性是 Git 的基础。 So the pushed master branch will necessarily "look like a graph", the commits on the local branch won't vanish into thin air.因此,推送的master分支必然“​​看起来像一张图”,本地分支上的提交不会凭空消失。

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:在您的示例中,假设没有提交 D 和 E,您合并本地分支,则历史记录变为:

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

Notice that there is no M either (no merge commit).请注意,也没有 M(没有合并提交)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我本地分支上已删除的提交是否也通过git推送到我的远程仓库中? - Do deleted commits on my local branch also get pushed to my remote repo with git? Git - 重命名有 2 个提交推送到远程的本地分支 - Git - Rename a local branch which has 2 commits pushed to remote 将其他分支合并到我的分支并将太多提交推送到远程 - Merged other branch to my branch and pushed too many commits to remote git pull将提交提交到远程分支 - git pull pushed commits to remote branch 如何获取所有 git 提交到合并分支的列表? - How do I get a list of all git commits to a merged branch? Git branch merged 列出合并时提交为零的本地分支 - Git branch merged list local branches with zero commits as merged 列出当前分支中尚未被Git工具推送到远程的所有本地提交 - List all local commits in the current branch that have not been pushed to remote for Git tool 我如何处理已合并的远程分支的本地提交? - What do I do with local commits for a remote branch that has been merged? 使用 Git,在我的代码提交合并到 master 分支后,我是否要删除我的远程分支,再次克隆 master 并检查下一个分支? - With Git, after my code commits are merged to the master branch, do I delete my remote branch, clone master again and checkout the next branch? GIT 修复本地分支(和远程)中的提交 - GIT fix commits in local branch (and remote)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM