简体   繁体   中英

git submodule not pushing into correct repo

I have a repo where I'm developing some library and I generate the /dist folder that I want then to push into another repo so that other apps can import only this.

So I read that adding this /dist as a submodule would be a way to do that.

My main folder (with my /src, package.json and so on) has a remote like this:

MINGW64 ~/Documents/myapp-dw (master)
$ git remote -v
origin  https://.../_git/myapp-dw (fetch)
origin  https://.../_git/myapp-dw (push)

now I add a submodule with

$ git submodule add https://.../_git/myapp-dw-dist dist

and a new .modules file is created with the information for the new module.

Next, I generate my dist folder with an npm task and the folder is created with the rest of the files inside.

I do git status and I see that folder /dist has been modified.

So I go to /dist and I run git add . and git commit

Next I do git push from my main folder and the /dist folder is pushed into my main repository instead of my dist repository.

What am I missing here? I thought this was supposed to go into myapp-dw-dist as I added it as a different submodule.

EDIT: Just in case, I have to say that every time I rebuild my /dist folder I'm removing the folder completely (rimraf) and create it again... is it possible I'm removing some sensitive git information? I was under the impression that all git needed was the .modules file.

After calling $ git submodule add https://.../_git/myapp-dw-dist dist , there should already exist a new folder dist . Everything that happens in this folder (and only things happening in this folder) will be pushed to the myapp-dw-dist repository.

You may, however, not have noticed the directory since it will be empty until you run $ git submodule init . This should make all the files from your myapp-dw-dist repo appear inside. Changes inside the folder can now be committed an pushed from within this folder (ie repository) .

After committing changes in the submodule, do not forget to commit the changed state of your submodule in the parent repository.

For more documentation on submodules, see here .

EDIT: Ah, there's the problem! As you say in your edit, when you delete the dist folder, you also delete the dist/.git folder. That is the folder telling git into which repository to push. As long as there's no .git folder in your submodule, git will think it's just another folder in your parent repository and push where everything else gets pushed.

You could either try to only delete the files inside dist instead of the whole folder, or re-add the submodule after every change (which does sound somewhat more error-prone).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM