从 git 存储库中的子文件夹提交 .git 文件夹
Commit .git folder from subfolder in git repository
下面是 git 存储库的结构,它在子文件夹 dir
.
中使用 git init
初始化了另一个 git 存储库
$ tree -a -L 2 .
.
├── .git
│ ├── HEAD
│ ├── config
│ ├── description
│ ├── hooks
│ ├── info
│ ├── objects
│ └── refs
└── dir
└── .git
如何从子文件夹提交和推送 .git
文件夹?
我尝试了 运行 git add dir/.git
和 git commit ..
,但就 git log
而言,什么也没做。
dir
中的存储库被一些需要 clone/checkout 从 dir
中的本地 git 存储库更改的工具用于部署。
根据 tutorial 使用 git 个子模块有帮助。
下面的命令序列说明了所需的测试流程:
$ mkdir git_repo
$ cd git_repo/
$:git_repo git init
Initialized empty Git repository in /private/tmp/git_repo/.git/
$:git_repo mkdir inner_repo
$:git_repo cd inner_repo
$:inner_repo git init
Initialized empty Git repository in /private/tmp/git_repo/inner_repo/.git/
$:inner_repo touch file
$:inner_repo git add file
$:inner_repo git commit -m 'initial'
[master (root-commit) 2b13943] initial
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file
$:inner_repo cd ..
$:git_repo git submodule add ./inner_repo
Adding existing repo at 'inner_repo' to the index
$:git_repo cd ..
$ git clone git_repo/inner_repo inner
Cloning into 'inner'...
done.
以下流程在 Bitbucket 中具有远程的现有本地存储库中实现了预期结果:
- 在父存储库中为内部存储库创建文件夹
- 复制一些文件到
inner_repo
- 初始化内部存储库并提交文件(在
inner_repo
运行 git init
和 git commit -am 'initial'
内)
- 转到父存储库:
cd ..
。
- 关键步骤:
git submodule add ./inner_repo ./inner_repo
之后上演了.gitmodules
和inner_repo
根据docs的解释:
git submodule add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--depth <depth>] [--] <repository> [<path>]
Add the given repository as a submodule at the given path to the
changeset to be committed next to the current project: the current
project is termed the "superproject".
The optional argument <path>
is the relative location for the cloned submodule to exist in the superproject. If <path>
exists and is already a valid Git repository, then it is
staged for commit without cloning.
下面是 git 存储库的结构,它在子文件夹 dir
.
git init
初始化了另一个 git 存储库
$ tree -a -L 2 .
.
├── .git
│ ├── HEAD
│ ├── config
│ ├── description
│ ├── hooks
│ ├── info
│ ├── objects
│ └── refs
└── dir
└── .git
如何从子文件夹提交和推送 .git
文件夹?
我尝试了 运行 git add dir/.git
和 git commit ..
,但就 git log
而言,什么也没做。
dir
中的存储库被一些需要 clone/checkout 从 dir
中的本地 git 存储库更改的工具用于部署。
根据 tutorial 使用 git 个子模块有帮助。
下面的命令序列说明了所需的测试流程:
$ mkdir git_repo
$ cd git_repo/
$:git_repo git init
Initialized empty Git repository in /private/tmp/git_repo/.git/
$:git_repo mkdir inner_repo
$:git_repo cd inner_repo
$:inner_repo git init
Initialized empty Git repository in /private/tmp/git_repo/inner_repo/.git/
$:inner_repo touch file
$:inner_repo git add file
$:inner_repo git commit -m 'initial'
[master (root-commit) 2b13943] initial
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file
$:inner_repo cd ..
$:git_repo git submodule add ./inner_repo
Adding existing repo at 'inner_repo' to the index
$:git_repo cd ..
$ git clone git_repo/inner_repo inner
Cloning into 'inner'...
done.
以下流程在 Bitbucket 中具有远程的现有本地存储库中实现了预期结果:
- 在父存储库中为内部存储库创建文件夹
- 复制一些文件到
inner_repo
- 初始化内部存储库并提交文件(在
inner_repo
运行git init
和git commit -am 'initial'
内) - 转到父存储库:
cd ..
。 - 关键步骤:
git submodule add ./inner_repo ./inner_repo
之后上演了.gitmodules
和inner_repo
根据docs的解释:
git submodule add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--depth <depth>] [--] <repository> [<path>]
Add the given repository as a submodule at the given path to the changeset to be committed next to the current project: the current project is termed the "superproject".
The optional argument
<path>
is the relative location for the cloned submodule to exist in the superproject. If<path>
exists and is already a valid Git repository, then it is staged for commit without cloning.