Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

Git/Github Redirecting subdirectories to other repositories

I keep the sub modules of a project in different repositories.

I host the sub modules in the Modules folder within the main project.

Submodules are ignored in the root project's .gitignore` file.

It's okay, but I want to create links to submodules on github.

I tried using Submodules. However, if I use submodules, I guess the folder contents (Modules/..) must be empty.

How can I do that?

My local workspace:

RootFolder << user/RootFolder
├── .git
├── README.md
├── .gitignore
├── composer.json
└── Modules
    ├── Module1 << user/Module1
    │   ├── .git
    │   ├── README.md
    │   └── composer.json
    └── Module2 << user/Module2
        ├── .git
        ├── README.md
        └── composer.json

RootFolder/.gitignore content:

/Modules

It looks like this on Github. (As it's supposed to be)

user/RootFolder
├── README.md
└── composer.json

However, I want to create links with the same name as the ignored folders:

user/RootFolder
├── .gitignore
├── Modules
│   ├── Module1 >> Redirect to https://github.com/user/Module1 (How can I do that?)
│   └── Module2 >> Redirect to https://github.com/user/Module2 (How can I do that?)
├── README.md
└── composer.json

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

1 Answer

0 votes
by (71.8m points)

To convert your existing folder structure to use proper submodules:

  1. Make sure that both the parent repository and the module repository do not have any changes. In other words, make sure that git status tells you that you have nothing to commit, working tree clean.

  2. Move the current module repository out of the way, to back it up. In other words mv Modules/Module1 Modules/Module1.bak.

  3. Add it as a submodule: git submodule add -f https://github.com/path_to/module1 Modules/Module1. The -f is needed since Modules still exists in your .gitignore.

  4. Make sure the file structure is as you like it. Run a build, test, etc. Run git status to make sure that the .gitmodules file and the module itself show up as staged changes. Commit the changes when you're happy with everything.

  5. Repeat starting at step one until you've converted all your submodules.

  6. Remove the backup module folders from the Modules directory.

  7. Remove /Modules from your .gitignore.

Congratulations(???) you now have submodules.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...