使用git子树时如何添加特定的文件夹? [英] How can I add a specific folder when using git subtree?

查看:84
本文介绍了使用git子树时如何添加特定的文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个复杂的离子项目.我正在开发的许多组件和提供程序都是通用的,可以在我公司正在进行的其他项目中使用.这在软件开发中很常见.这是我想出的Git工作流程(此图显示了分支):

I have a complicated Ionic project I'm developing. Many of the components and providers I'm developing are generic and can be used in other projects my company is doing. This is common in software development. This is the Git workflow I have come up with (this graph shows branches):

my-company-library-repo ----
                            |_ component 1 feature branch
                               |_ company component 1 feature branch testbed
                            |_ component 2 feature branch

在测试平台中开发的最终组件代码(只是.ts.js文件)被推送到组件功能分支.测试平台代码保留在测试平台分支中.在功能分支中还会出现该组件可能附带的所有文档.

The final component code (just a .ts or .js file) developed in the testbed is pushed to component feature branch. The testbed code stays in the testbed branch. Also in the feature branch goes any docs that might accompany the component.

现在在应用程序仓库中,我使用以下命令将功能分支添加为子树:

Now in the application repo I add the feature branch as a subtree using this command:

git subtree add -P <destination-dir/feature> --squash <my-company-library-repo-url> <feature-branch-name>

这给了我以下信息(此图显示了文件夹结构):

And that gave me the following (this graph shows folder structure):

my-app-repo-------
                  |_ company-library-feature-subtree

这应该只包含.js.ts,并且它是其子文件夹中的文档.我得到这个只是部分工作.当它拉出子树时,它只会拉出组件及其doc文件,但是文件会被拉入非常长的子目录列表中,如下所示:

This should only contain the .js or .ts and it's docs in it's subfolder. I get this only to work part way. When it pulls the subtree, it does only pull the component and it's doc files, but the files get pulled into a very long list of sub-directories like this:

my-app-repo/src/feature-branch/feature/src/app/providers/...

这使使用该库变得很困难,因为文件的目录太多了(未使用的目录).

This makes it hard to use the library because the files are put so many directories (unused directories) deep.

因此,当我将2个文件从feature-testbed分支推送到feature分支时,我如何不能用它们拉整个目录结构?

So, when I push my 2 files from the feature-testbed branch to the feature branch, how can I not pull that whole directory structure with them?

推荐答案

我研究了Scott Weldon的解决方案.它将起作用,但是git子树似乎将所述目录拆分为自己的存储库.至少那是我从阅读手册和书本中学到的东西,而并非如此. (如果我错了,可能就是这种情况,请让我知道.)那不是我想要做的.

I researched Scott Weldon's solution. It would work, but it seems git subtree splits the said directory into its own repo. At least that's what I gleaned from reading man pages and books and what not. (If I'm wrong, which may well be the case, please let me know.) That's not what I wanted to do.

但是,我确实找到了解决问题的方法.这是我在项目中使用Git子树合并策略(而不是GIT SUBTREE命令)所做的事情:

I did, however, find the solution to my problem. Here's what I did using the Git Subtree Merge Strategy (instead of the GIT SUBTREE command) in my project:

$ git remote add my-library <my-library-url>
$ git fetch my-library
$ git checkout -b my-library-branch my-library/master
$ git checkout master
$ git read-tree --prefix=<desired/library/dir> -u my-library-branch
$ git commit -m "Merged library project as subdirectory"
$ git push

效果很好.我的图书馆在合理的子文件夹中.诚然,我必须带走整个库,而不仅仅是像自定义组件或提供程序这样的大块,在这种情况下就可以了.

This worked great. I have my library in a reasonable subfolder. Admittedly, I have to take the whole library, not just a chunk like a custom component or provider, but that's OK in this case.

这篇关于使用git子树时如何添加特定的文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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