why does Git send whole repository each time push origin master

人走茶凉 提交于 2020-01-04 04:20:07

问题


I commit a few changes locally and then push to github using 'git push origin master'. It always pushes the complete code base (judging by the amount of data transferred).

I must be missing something simple.. should only push up the changed files..?


回答1:


That is a mystery to me too. My colleague has found that creating tracking branches helps:

http://www.zorched.net/2008/04/14/start-a-new-branch-on-your-remote-git-repository/

EDIT I found that this happens when I don't pull before creating a remote branch. If I pull first, it sends barely anything.




回答2:


If you're looking at the number of "objects" that Git sends up to the remote, then this may be misleading you. Git creates an object not only for every file in your commit, but also for every directory (tree), every commit, and every tag. If you're doing operations such as merges, you may also have somewhat more commits than you may expect.

How big is your repository? What numbers are you looking at to judge the amount of data?




回答3:


Git versions whole file trees, and each commit points to a complete snapshot of a tree. Git then relies on compression for keeping the size of the repository down. So the data that needs to be transfered when you push are these snapshots, rather than diffs. In effect, Git asks the server what its newest commit is and then sends all the local commits in that branch that are built on top of that. The objects are probably compressed when they are transfered, but they are still snapshots.

That is at least my understanding.




回答4:


this might be a trivial answer, but I think the mistake I've been making is to "git add ." befor commiting changes.

if I "git add filename" and then commit when I "git push origin master" only this file is transfered to github.



来源:https://stackoverflow.com/questions/1381403/why-does-git-send-whole-repository-each-time-push-origin-master

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!