git push 和 git pull 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11240715/
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 the difference between git push and git pull?
提问by Qw4z1
I just stumbled over something peculiar today. I asked a co-worker at my summer job to help me set up a new remote git repo for my code and there was a lot of confusion about what he did and what I wanted to do. I asked him to send over his config to be able to see the path to his remote and found out that he didn't have a remote. When I asked him about this he explained his workflow like this:
我今天偶然发现了一些奇怪的东西。我在暑期工作时请一位同事帮助我为我的代码设置一个新的远程 git 存储库,但对他做了什么以及我想做什么有很多困惑。我让他发送他的配置,以便能够看到他的遥控器的路径,并发现他没有遥控器。当我问他这个问题时,他这样解释了他的工作流程:
- Change something locally
- Commit
- Move to remote dir
- git pull c:\localdir
- 在本地改变一些东西
- 犯罪
- 移动到远程目录
- git pull c:\localdir
So instead of pushing to a remote he constantly pulled from his local repo to the one on our server. Sort of working backwards. When I confronted him about this he asked me what the difference was and I could not really answer him, but I think there are something right?
因此,他没有推送到远程,而是不断地从他的本地存储库拉到我们服务器上的存储库。有点倒退。当我就此事质问他时,他问我有什么不同,我无法真正回答他,但我认为有些事情是对的?
So my question to you all is: What is the difference in pushing to a remote and pulling from a remote?
所以我对你们所有人的问题是:推到遥控器和从遥控器拉有什么区别?
采纳答案by Dolanor
Pushing to a remote : send some commits you have to a another git repo. The git repo is considered as "remote", but it can be a repo in another folder of your hard drive. pulling from a remote : get some commits from a remote repo and merge them in your current HEAD (your current checkout of your repo)
推送到远程:将一些提交发送到另一个 git 存储库。git repo 被视为“远程”,但它可以是硬盘驱动器另一个文件夹中的一个 repo。从远程拉取:从远程仓库获取一些提交并将它们合并到您当前的 HEAD(您当前的仓库签出)中
Your coworker might have use pull instead of push because your repository might not have been available (no git daemon running, or gitweb, or ssh server on), but his was avalaible from your computer. As it is a server, he might not want to expose a git daemon/service which could be a vector of attack.
您的同事可能使用 pull 而不是 push,因为您的存储库可能不可用(没有运行 git 守护程序,或 gitweb 或 ssh 服务器),但他可以从您的计算机上获取。因为它是一个服务器,他可能不想暴露一个 git 守护进程/服务,这可能是一个攻击向量。
But if your repository was shared/available, he would just have been able to do :
但是,如果您的存储库是共享/可用的,他就可以这样做:
- change something locally
- commit
- push to your repository
- 在本地改变一些东西
- 犯罪
- 推送到您的存储库
回答by Miquel
In my view you can either let users push their commits to some repository that's considered to be "the master", or you let them send pull requests to a single user that has permission to modify said "master".
在我看来,您可以让用户将他们的提交推送到某个被认为是“主”的存储库,或者让他们向有权修改所述“主”的单个用户发送拉取请求。
Github, for example, won't let non-contributors push to the repository, but will allow them to send pull requests, so that the contributors can integrate their changes.
例如,Github 不会让非贡献者推送到存储库,但允许他们发送拉取请求,以便贡献者可以集成他们的更改。
回答by iain
None, the repos are copies of each other and pull and push are just direction flows. The difference with your co-worker's method is that he added a 4th unneeded command.
没有,repos 是彼此的副本,pull 和 push 只是方向流。与您同事的方法不同的是,他添加了第 4 个不需要的命令。
回答by eckes
Yes, it is working backwards.
是的,它正在倒退。
Principle workflow is:
主要工作流程是:
- change something locally
- commit
- push to remote dir
- 在本地改变一些东西
- 犯罪
- 推送到远程目录
One use case (another is explained by Dolanor) for not pushing to remote is that a working copy is checked out on the remote (i.e. it's no bare repo). When he wants to push a branch that is checked out on the remote box (e.g. master:master
), this will not succeed since pushes to checked-out branches are forbidden.
一个不推送到远程的用例(另一个由 Dolanor 解释)是在远程签出工作副本(即它不是裸仓库)。当他想推送在远程框(例如master:master
)上签出的分支时,这将不会成功,因为禁止推送到签出的分支。
In my opinion, that's the only use case for hopping over to the remote machine and pulling instead of pushing from the local machine.
在我看来,这是跳到远程机器并从本地机器拉取而不是推送的唯一用例。