Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.0k views
in Technique[技术] by (71.8m points)

version control - How would you keep two slightly different repositories updated with the folders/files that they have in common?

Basically, I have two separate repositories. They're both running FeathersJS, and are slightly different. I was wondering if there was a way to update both repositories if one of the services in one repository is updated, if that service is shared in common with both repositories. Thanks!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Option One: Git

You don't specify the version control system you're using but I'll assume it's Git since that is by far the most popular.

When using Git, there's a way to "embed" repositories within one another so they can be used as-if the code is saved directly in the parent, but is really under it's wn version control. This is called git submodules and whilst it's a great solution, it's also quite complex and may be overkill for what you want.

Basically, you would go from a structure like this:

| - repo1
    | - shared file
| - repo2
    | - shared file

To this:

| - repo1
    | - git submodule: repo3
| - repo2
    | - git submodule: repo3
| - repo3
    | - shared code

Option Two: NPM

Since you specified you're working with Javascript, you could also use the Javascript package manager; NPM. NPM allows you to "package" code up and then import it into other projects.

NPM is by far more popular than git submodules and learning how to use it will be a valuable skill if you intend to work with modern JS.

In this case, you would move the shared code to a new repo (as you would with Git submodules, above) and then package it and publish it.

Then, you can import this packaged code into your two existing repos.

NPM requires you to have NodeJS installed and that you have a build process in place to import the NPM package and pack everything up in a way your browser can handle it.

Check out the NPM getting started guide for more info.

Feel free to ask any questions in the comments ??


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...