git push到底会发生什么?为什么不像git merge一样考虑git push? [英] What exactly happens in a git push? Why isn't a git push considered just like a git merge?

查看:709
本文介绍了git push到底会发生什么?为什么不像git merge一样考虑git push?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,如此处所述,git pull只是获取最新内容,然后合并它们. git push不一样吗?即从远程...您获取本地并将其合并到分支中?

So as mentioned here a git pull is just fetching the latest and then merging them. Isn't that the same for a git push? ie from the remote...you fetch the local and merge it into the branch?

还是您没有合并任何内容,而是完全重写了提交的历史记录……忽略了那里的任何内容,只是用一个新的提交列表替换了提交列表?

Or is that you're not merging anything, rather you're totally re-writing history of commits...ignoring whatever was there and just replacing commit lists with a newer one?

(我完全知道何时使用git push,即在完成本地功能后使用.我深入了解我的问题.我的问题更多是关于幕后发生的事情)

(I'm fully aware of when to use git push ie I use when I'm done with a feature in my local. I push into my origin. My question is more about what happens under the hood)

推荐答案

git pull 拉动从远程到本地客户端的最新提交.

git pull pulls the latest commits from the remote to your local client.

git push 从您的本地客户端推送到远程.

git push pushes your latest local commits from your local client to the remote.

当您push时,如果本地存储库中没有来自远程的所有提交,则push被拒绝,不会像您认为的那样合并到远程分支中.在这种情况下,您必须首先pull遥控器的最新更改,然后mergerebase您的本地更改.现在,您的本地存储库位于远程服务器的前面,您可以继续进行push.

When you push, if your local repository does not have all commits from the remote, the push is rejected, not merged into the remote branch as you seem to think. In this case you must first pull the remote's latest changes and either merge or rebase your local changes. Now your local repository is ahead of the remote and you can proceed to push.

在本地和远程历史记录匹配的特殊情况下,您可以将pushpull相对地看,即,远程从本地拉"出更改,而您说得对这个案例.合并策略等同于pull从远程进行新更改(具体来说,合并策略为fast-forward;有关中途此页面).但是,远程仓库无法完全像本地仓库一样工作,无法登录到远程仓库和pull.而是命令是在本地运行,因此我们必须使用正确的动词push.

In the special case where local and remote histories match, you could look at the push as symmetrically opposite to the pull, i.e. the remote "pulls" the changes from the local, and you're right that in this case. The merge strategy would be equivalent to pulling new changes from remote (specifically the merge strategy is fast-forward; explained about halfway down this page). However a remote repo doesn't work exactly like a local repo, there's no way to login to the remote and pull; rather the command is being run on the local so we must use the correct verb, push.

这篇关于git push到底会发生什么?为什么不像git merge一样考虑git push?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆