简体   繁体   English

如何Git将下载的文件推送到远程?

[英]How to Git Push Downloaded files to Remote?

I have a big project on bitbucket.org which is around 2GB. 我在bitbucket.org上有一个大项目,大约2GB。 For some reason, git clone command breaks in between. 由于某些原因,git clone命令在两者之间中断。 So I decided to download the source files in a zip version provided by bitbucket. 因此,我决定以bitbucket提供的zip版本下载源文件。

Now what I want to do is that whatever changes I made to these files, I want to upload them to the Git repo over bitbucket. 现在,我要做的是,无论我对这些文件进行了什么更改,我都想通过bitbucket将它们上传到Git存储库中。

Here is what I just tried: 这是我刚刚尝试过的:

  1. I extracted all files from zip to a folder "myproject" 我将所有文件从zip提取到文件夹“ myproject”

  2. Then I run a below command git commands in this folder 然后我在此文件夹中运行以下命令git命令

git init git初始化

git add . git添加

git commit -m "test commit" git commit -m“测试提交”

so this step initialized a local git repository for me for those downloaded files. 因此,此步骤为我为这些下载的文件初始化了本地git存储库。

  1. Then I run the below command to set up the remote repository 然后我运行以下命令来设置远程存储库

git add origin https://xyz@bitbucket.org/myproject/myproject.git git添加来源https://xyz@bitbucket.org/myproject/myproject.git

  1. Now I type below command to push the changes to remote repository 现在,我键入以下命令将更改推送到远程存储库

git push origin master git push origin master

This all runs fine but the problem is in the last step, it uploads the whole project to remote repo in place of uploading just the files that were updated. 一切运行正常,但问题出在最后一步,它将整个项目上载到远程存储库,而不是仅上载已更新的文件。

How do I fix this so that it can upload only the files that are changed? 如何解决此问题,使其只能上传已更改的文件?

The direct answer is you can't only upload (push) the changed files and it's not the way git works. 直接的答案是您不仅可以上传(推送)更改的文件,而且不是git的工作方式。

A git commit only calculate the changes of files and then use checksume as SHA_1 value. git commit仅计算文件的更改,然后将校验和用作SHA_1值。

the commit records the snapshot you set up in your staging area. 提交记录您在临时区域中设置的快照。 Anything you didn't stage is still sitting there modified; 您没有上演的所有内容仍坐在那里进行修改; you can do another commit to add it to your history. 您可以再次提交以将其添加到您的历史记录中。 Every time you perform a commit, you're recording a snapshot of your project that you can revert to or compare to later 每次执行提交时,都会记录项目的快照,以后可以还原或比较该快照

So the unchanged files has tiny effect for the size of a git repo. 因此,未更改的文件对于git repo的大小影响很小。 If you want to make the huge repo slim, you should find some fat commits in commit histories, and then find the biggest file and remove them in all commit histories. 如果您想缩小大型存储库,则应在提交历史记录中找到一些繁琐的提交,然后找到最大的文件并在所有提交历史记录中将其删除。 More details you can refer removing objects part in this chapter . 更多详细信息,请参阅本章中的“删除对象”部分。

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

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