git中的依赖项 [英] Dependencies in git

查看:198
本文介绍了git中的依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过git管理自己的个人小站点,更多的是作为学习体验,而不是这样做的任何实际优势。我的工作流程通常是:


  1. 在我的桌面上进行更改

  2. 测试文件:///路径/ to /文件夹放在我的
    浏览器中,并根据需要添加/提交/更改

  3. 当我很高兴时,将
    推到原点,成为EC2实例,其中提交后的
    钩子更新工作树

我想使用 MathJax 在我的网站上显示数学公式,但MathJax文件夹是128Mb,而我的项目其余部分几乎完全不包含1Mb。此外,MathJax /包含许多小文件,并且(因为它进入了我的工作树)像git add和git status的运行速度非常缓慢 - 我假设因为git需要单独检查每个文件的状态。



在添加MathJax之前,我试图将 git reset --hard 添加到提交中,从我的git中排除MathJax文件夹repo(.gitignore),并且只需手动将其添加到我的网络服务器,理由是我不会经常更改MathJax,并且将其添加到回购库似乎会为其他快速操作增加相当大的开销。再说一次,这意味着我的回购并不是一个独立的实体,这在概念上似乎是错误的 - 我知道我下载一个美观的新脚本或服务时会感到沮丧,然后我必须在它之前搜索15个依赖关系将会运行。



很显然,没有其他人会在这个特定的回购站上工作,但是我仍然想要养成良好的习惯。在这种情况下最好的做法是什么?是否应该将大的依赖关系包含在回购中?如果不是,引用它们的最佳方式是什么 - README.md?

解决方案

引用git书:


经常发生的情况是,在处理一个项目时,您需要使用
中的另一个项目。也许这是一个图书馆,开发了第三个
派对或者你正在单独开发并使用
多个父项目。在这些情况下出现了一个常见问题:
您希望能够将两个项目分开处理,但仍然可以使用另一个项目中的


blockquote>

您需要使用一个名为submodules的git功能。它是另一个git仓库中的git仓库。请参阅 Git book 手册页了解详情。

其他选项是git子树(不要与子树合并混淆)。它在1.7.11及更高版本的git中可用。一篇很好的博客文章,描述了子树的使用: https ://blogs.atlassian.com/2013/05/alternatives-to-git-submodule-git-subtree/


I'm managing my own personal small site via git, more as a learning experience than for any real advantages in doing so. My workflow is generally:

  1. Make changes on my desktop
  2. Test file:///path/to/folder in my browser, and add/commit/change as appropriate
  3. When I'm happy, push to origin, which I've set to be an EC2 instance, where a post-commit hook updates the working tree

I want to use MathJax to display maths equations on my site, but the MathJax folder is 128Mb, while the rest of my project barely comprises 1Mb altogether. Moreover, MathJax/ contains many small files, and (since it entered my working tree) operations like git add and git status are running very slowly - I assume because git is having to check every one of the files individually for status.

I'm tempted to git reset --hard to the commit before adding MathJax/, exclude the MathJax folder from my git repo (.gitignore), and simply add it to my webserver manually, on the grounds that I won't be changing MathJax regularly, and adding it to the repo seems to add considerable overhead for otherwise speedy operations. Then again, this means that my repo is not a self-contained entity, which seems conceptually wrong - I know how frustrated I get when I download a tasty-looking new script or service, and then I have to hunt down fifteen dependencies before it will run.

Obviously, no-one else is going to be working on this particular repo, but I'd like to get into good habits nonetheless. What's the best practice in a situation like this? Should large dependencies be included in a repo? If not, what's the best way of referring to them - README.md?

解决方案

Quoting the git book:

It often happens that while working on one project, you need to use another project from within it. Perhaps it’s a library that a third party developed or that you’re developing separately and using in multiple parent projects. A common issue arises in these scenarios: you want to be able to treat the two projects as separate yet still be able to use one from within the other.

You need to use a git feature called submodules. It's a git repository inside another git repository. See the Git book or the man pages for details.

Other option is git subtree (not to be confused with subtree merging). It's available in git versions 1.7.11 and later. A nice blog post describing the use of subtree here: https://blogs.atlassian.com/2013/05/alternatives-to-git-submodule-git-subtree/

这篇关于git中的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆