简体   繁体   English

如何在不同步本地/远程仓库的情况下推送到 github

[英]how to push to github without sync local/remote repo

I've a git folder in my pc that contains directory called work.我的电脑中有一个 git 文件夹,其中包含名为 work 的目录。 Each 10mn a file will be generated and added to work directory.每 1000 万个文件将生成并添加到工作目录。

I need to push to github the new file generated in my work dir each 10mn then my automation script will remove it from my local work dir.我需要每 1000 万次将在我的工作目录中生成的新文件推送到 github,然后我的自动化脚本会将其从我的本地工作目录中删除。

The problem is I'll only get the last file on my github each 10mn and not all of them.问题是我每 1000 万次只能获得 github 上的最后一个文件,而不是全部。

what i want is:我想要的是:

#at t=10
file1 added to work git directory.
push it to github 
delete it from work dir

#at t=20
file2 added to work git directory.
push it to github 
delete it from work dir

#at t=30
file3 added to work git directory.
push it to github 
delete it from work dir


then i'll have test1, test2 and test3 on github (this is what i want, but i get only file3 now or the last push file).

The file add & deletion works perfectly and done with my automation script. My only problem is the one i mentioned above.

Git does not work with files—not the way you're thinking, that is. Git 不适用于文件——不是你想的那样。 Git does not even work with folders full of files , although this is closer. Git 甚至不适用于充满文件的文件夹,尽管这更接近。 The issue here is that Git works with commits .这里的问题是 Git 与commits一起工作。 The git push operation pushes some commits . git push操作推送一些提交 Your repository on your local PC stores commits and your (separate) repository over on GitHub stores commits .您在本地 PC 上的存储库存储提交,而您在 GitHub 上的(单独)存储库存储提交 So you must think in terms of commits, not files.所以你必须考虑提交,而不是文件。

Each commit acts like an archive of all files .每个提交就像所有文件的存档一样。 That is, given some commit—they're numbered—you ask Git to extract that commit, and Git gets the full archive of every file as stored in that commit.也就是说,给定一些提交(它们已编号),您要求 Git提取该提交,然后 Git 获取存储在该提交中的每个文件的完整存档

If you make a commit on Tuesday, and that commit contains files f1 , f2 , and f3 , then Tuesday's commit contains files f1 , f2 , and f3 .如果您在星期二提交,并且该提交包含文件f1f2f3 ,则星期二的提交包含文件f1f2f3 It contains those files, in the form they had when you made the commit .它包含这些文件,格式为您提交时的格式 It contains exactly those files forever .永远包含这些文件

If you make a different commit on Wednesday, and that commit contains files f3 , f4 , and f5 (but not f1 or f2 ), that commit contains those files, in that form, forever .如果您在周三进行了不同的提交,并且该提交包含文件f3f4f5 (但不包括f1f2 ),则该提交包含这些文件,形式为forever It never contains f1 and f2 .从不包含f1f2

The commits act as snapshots , holding every file, frozen in time.提交充当快照,保存每个文件,及时冻结。 That's the #1 most important point of any version control system: it lets you "go back in time" and see what all your files looked like on Wednesday.这是任何版本控制系统中#1 最重要的一点:它可以让您“回到过去”并查看周三所有文件的样子。 These files are literally frozen: you can't write to them, and not even Git can write to them.这些文件实际上是冻结的:您无法写入它们,甚至 Git 也无法写入它们。 To save space—among other reasons—Git stores them in a special format where only Git can read them too: they're compressed and, importantly, de-duplicated so that if Wednesday's files include all of Tuesday's files, they don't take any extra space for the duplicates.为了节省空间——除其他原因外——Git 以一种特殊的格式存储它们,只有Git也可以读取它们:它们被压缩,重要的是,去重,因此如果周三的文件包含周二的所有文件,它们不会占用重复项的任何额外空间。

Now, obviously, to get any work done, you can't use a frozen-in-time set of files.现在,显然,要完成任何工作,您不能使用即时冻结的文件集。 So that's not how you do work with Git.所以这不是使用 Git 的方式。 Instead, you tell Git: extract a commit so that I have usable, read-able, write-able files .相反,您告诉 Git:提取提交,以便我拥有可用、可读、可写的文件 You pick the commit—usually the latest and greatest of course—and Git extracts all those files.您选择提交——当然通常是最新最好的提交——然后 Git 会提取所有这些文件。

You should not remove files unless you want the next commit to explicitly lack those files.除非您希望下一次提交明确缺少这些文件,否则不应删除文件。 Git will store the next commit's re-used copies of today's files without taking any space, if they're all duplicates. Git 将存储下一次提交的今天文件的重复使用副本,而不占用任何空间,如果它们都是重复的。 Removing files won't save any space because they're stored forever in the old commits.删除文件不会节省任何空间,因为它们永远存储在提交中。

So that's what's going on here: you're making each commit as an archive of one file, omitting all the previous files.这就是这里发生的事情:您将每个提交作为一个文件的存档,省略所有以前的文件。 Extracting the latest archive gets you just that one file.提取最新的存档只为您提供一个文件。 If that's not what you want, stop doing that.如果那不是您想要的,请停止这样做。

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

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