简体   繁体   中英

Can I add a file to my local Git repo but not push it to remote

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.

Not using conventional git methods. Having the file in the repo would change every commit hash following it. This would then not match up on the server side. I'd consider working around why you need them to live in the same repo that you have to push around.

You could have them in a separate repo that was then pulled in via a local git hook if it's for processing? If you elaborate your situation in your question we can probably help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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