How can I add a specific folder when using the git subtree?

I have a complex Ionic project that I am developing. Many components and suppliers that I develop are general in nature and can be used in other projects that my company does. This is common in software development. This is the Git workflow that I came up with (the branches are shown in this graph):

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

The final component code (only a file .tsor .js) developed in the test bench is transferred to the component branch. The code of the tested program remains in the testing branch. Also, any documents that may accompany the component go to the function branches.

Now in the application repository I add the function branch as a subtree using the following command:

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

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

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

It should contain only .jsor .ts, and it documents the subfolder. I only get this for partial work. When it pulls out a subtree, it only pulls out the component and the doc files, but the files are pulled into a very long list of subdirectories, such as:

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

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

So, when I push my 2 files from the Feature-testbed branch to the function branch, how can I not pull out the entire directory structure from it?

+4
source share
2 answers

. , , git . , , , . ( , , , .) , .

. , git Subtree Merge Strategy ( git SUBTREE) :

$ 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

. . , , , , .

+3

my-app-repo my-company-library-repo:

# In my-company-library-repo
git subtree split -P src/app/providers/... -b feature-new feature

src/app/providers/... , feature feature-new .

my-app-repo:

# In my-app-repo
git subtree add -P <destination-dir/feature> --squash <my-company-library-repo> feature-new

src/app/providers/... <destination-dir/feature>.

, , . git-subtree man:

(.. ). - , , , , , , , "git merge" .

+3
source

Source: https://habr.com/ru/post/1658962/


All Articles