Maintaining a Git repo inside another git repo

后端 未结 3 1414
天命终不由人
天命终不由人 2020-12-13 15:11

I have a git repo which contains an AngularJS web app.

It has a subfolder called build, which gets created by a gulp task. I am deploying to Azure, so

3条回答
  •  执念已碎
    2020-12-13 15:49

    While the documentation on this is extensive [https://git-scm.com/book/en/v2/Git-Tools-Submodules], I found the solution was to understand how submodules work. This is a simplified plain english version.

    1. If you have your main repo, you have already initialised it with git ($ git innit) you may be getting an error if you have added another initialised repo as a submodule
    2. If you add a submodule which already has an initialised git repo you might want to remove git tracking ($ cd into the sub module then $rm -rf git) this force removes the files tracked by git - or before you add it to the repo remove the initialisation
    3. Check what exactly is going on with $ git diff / $ git diff --cached / $ git diff - - submodule if you have cached files the documentation runs you through what to do
    4. If you have a submodule that is not being tracked (which was my challenge) the documentation suggests creating a separate branch and merging this branch to master - this is what I did some of the steps which are here are not in the documentation as the documentation assumes a certain level of knowledge of git and it took me a while to figure out all the steps left out when I was starting learning git.
        $ git checkout -b stable (create a new branch called stable)
        $ git checkout stable (check into the new branch)
        $ cd .. (into your branch with the submodules)
        $ git submodule update --remote --merge (update and merge the submodule to the remote branch)
        $ git add . (add all files and directories  to the branch)
        $ git commit -m”adds submodule to new branch” (commit changes in the branch)
        $ git push (push changes in the branch) - this will remind you make the stable branch your upstream 
        $ git push --set-upstream origin stable (set upstream to your new branch)
        $ git checkout master (checkout into the master branch)
        $ git merge stable (merge pushed changes from branch to master)
        $ git add . 
        $ git commit -m”adds submodules from merged stable branch”
        $ git push origin master
    
    • Go into your online repo and check that you have the files.
    • If this is not the challenge you faced (adding an already initialised git module to a repo) it is a bit of a slog reading the documentation but worth it if you fix the challenge. Hope this helps anyone who has added an already initialised git submodule to a main git repo.

提交回复
热议问题