问题
I have a big project(let's say A repo
), and it there one child folder which is come from B repo
. I would meet warning like below when I commit from A repo
warning: adding embedded git repository: extractor/annotator-server
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint:
hint: git submodule add <url> extractor/annotator-server
hint:
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint:
hint: git rm --cached extractor/annotator-server
hint:
hint: See "git help submodule" for more information.
I have seen git-submodule
and git-subtree
:
Maintaining Git repo inside another git repo
https://www.atlassian.com/blog/git/alternatives-to-git-submodule-git-subtree
But I don't like them , because they need extra config.
What I want is , for example:
structure like:
A/
--- a.py
--- B/
--- B/b.py
When I change B/b.py
.
If I am on path
A/
,git add
can detectB/b.py
changed,git push
only commit that to A repo.git add . (would add changes under A/ ) git push (would push changes under A/ ) git pull (would pull changes under A/ ) git clone XXX:A (would clone all files under A/ , A/B/ is just looks like plain folder with all files, not a repo )
If I am on path
A/B/
,git add
only addB/b.py
changes to B repo, andgit push
only commit that to B repo.git add . (would add changes under B/ , but not add changes to A repo) git push (would push changes under B/ , but not push changes to A repo) git pull (would clone changes under B/ , ) git clone XXX:B (would clone all files under B/ )
Once I want to snyc A and B in another machine, just do
git clone A rm -rf A/B/ git clone B ./B git add . && git commit 'sync with B'
In another word, A and B act as a standalone repo.
But the truth is , A repo treat B repo as submodule:
A repo https://github.com/eromoe/test
B repo https://github.com/eromoe/test2
How do I force A repo track all files under A/
, and B repo track all files under A/B/
? I want A and B act as a self-contain repo , without any other config.
回答1:
You can use below commands to add files from test2 repo to test repo as below:
# In local test repo
rm -rf test2
git clone https://github.com/eromoe/test2
git add test2/
git commit -am 'add files from test2 repo to test repo'
git push
Note:
You should use git add test2/
(with slash, not git add test2
).
git add test2/
will treat test2
folder and it's files as ordinary folder and file for test repo (create mode 100644
).
git add test2
will treat test2
folder as a submodule for test repo (create mode 160000
).
回答2:
Probably, git reminded the repository. It helped for me:
git rm --cached your_folder_with_repo git commit -m "remove cached repo" git add your_folder_with_repo/ git commit -m "Add folder" git push
回答3:
If you don't care about the exact version of B A is using, you can keep your current setting (nested git repos).
You will have the "embedded repo" warning, but beside that, both repos will behave as you expect, each one adding, committing and pushing only their repos.
Note: you can make that warning shorted/empty with git config advice.addEmbeddedRepo
来源:https://stackoverflow.com/questions/47008290/how-to-make-outer-repository-and-embedded-repository-work-as-common-standalone-r