问题描述
我有很多大型视频文件,我不想将它们推送到远程位置,但我希望将它们添加到本地存储库。有点像
.gitignore 并不妨碍你在你的仓库中拥有一个文件(你总是可以强制它)。所以这不是一个 .gitignore 在远程。
你的问题的直接答案是,这是不可能的。你的提交每一个提交都是通过它的内容进行的(如果你有一个提交文件,并且你推送了这个提交,你不能要求git只推送那个提交的一部分,因为那样它就不会不管怎么样,都是同样的提交。
然而,有些方法可以实现你想要的,但其中没有一个是非常干净的。一个例子是用git子模块创建子模块指向另一个位置你有回购(与视频文件)。任何克隆你的远程仓库的人都不会收到视频文件,但他们仍然可以看到指向你计算机某个地方的子模块。
另一种方法是使用git subtree实际上从您拥有的内容中创建另一组提交,不包括视频,然后将这些人工提交的提交推送到您的存储库。然而,它强加了一些目录结构。
这个问题的常见答案通常是重新考虑您的存储库。这些视频对您的存储库至关重要吗?如果没有,那么不要将它们放在存储库中,既不是本地的,也不是远程的。像这样的额外资源不属于git存储库(特别是因为它们也没有版本)。
如果您只希望在您的本地计算机中使用它们,只是让他们在其他目录。如果你真的想要访问旧版本,请将其他目录保留在git下。如果您希望其他人也看到这些文件,请将它们放在文件共享网站上。
I have a number of large video files which I don't want to push to my remote, I do however want to add them to my local repository. Kind of like a remote version of the .gitignore file.
Is that possible?
To be more specific, I'm working on a multimedia project and one folder has project metadata files (it's a Screenflow project) as well as media. So it has a project.screenflow folder with both .dat files and Media\XXXX.aif, Media\XXXX.mov etc.
I want to share at least the project files (.dat) with my team and it doesn't make sense to open the project up in Screenflow if you don't have the media it uses. However, there's a filesize limit of 100MB on our Git repo preventing me pushing those.
Currently, I've excluded Media in the .gitignore and may have to share the media by some other means :(
.gitignore doesn't prevent you from having a file in your repository (you can always force it). So this is not really like a .gitignore in the remote.
The immediate answer to your question is that it's not possible. Git keeps a history of your commits. Every commit is made (and hashed) by its contents. If you have a file in a commit, and you push that commit, you can't ask git to push only part of that commit, because then it wouldn't be the same commit anymore.
However, there are ways to achieve what you want, none of which are very clean. One example is with git submodules where you create a submodule that points to another local repo you have (with the video files). Anyone cloning your remote repo would not receive the video files, but they still see the submodule that refers to somewhere in your computer.
Another way would be to use git subtree to actually create another set of commits from the ones you have, excluding the videos, and then push those artificially made commits to your repository. It however imposes some directory structure.
The usual answer to such a question often is to rethink your repository. Are the videos vital to your repository? If not, then don't put them in the repository, neither local nor remote. Extra resources like that don't belong in a git repository (especially since they are also not versioned).
If you only want them in your local computer, by all means just keep them in some other directory. If you really want to have access to old versions, keep that other directory under git on its own. If you want others to see the files too, put them on a file sharing website.
这篇关于我可以将文件添加到本地Git仓库,但不能将其推送到远程仓库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!