[英]Commit .git folder from subfolder in git repository
Below is structure of git repository which has another git repository initialized using git init
in subfolder dir
.下面是 git 存储库的结构,其中有另一个 git 存储库使用
git init
在子文件夹dir
中初始化。
$ tree -a -L 2 .
.
├── .git
│ ├── HEAD
│ ├── config
│ ├── description
│ ├── hooks
│ ├── info
│ ├── objects
│ └── refs
└── dir
└── .git
How to commit and push .git
folder from the subfolder?如何从子文件夹提交和推送
.git
文件夹?
I tried running git add dir/.git
and git commit..
, but nothing was commited as far as git log
is concerned.我尝试运行
git add dir/.git
和git commit..
,但就git log
commit.. 而言,没有提交任何内容。
Repository inside dir
is used in deployment by some tool which needs to clone/checkout changes from local git repository in dir
. dir
中的存储库用于部署某些工具,该工具需要从dir
中的本地 git 存储库克隆/签出更改。
Using git submodules according to tutorial helped.根据教程帮助使用 git 子模块。
Below sequence of commands illustrates the required test flow:下面的命令序列说明了所需的测试流程:
$ 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.
Below flow achieved the desired result in existing local repository which had remote in Bitbucket:以下流程在 Bitbucket 中具有远程的现有本地存储库中实现了预期的结果:
inner_repo
inner_repo
inner_repo
run git init
and git commit -am 'initial'
)inner_repo
内部运行git init
和git commit -am 'initial'
)cd..
. cd..
git submodule add./inner_repo./inner_repo
git submodule add./inner_repo./inner_repo
After that .gitmodules
and inner_repo
were staged.之后
.gitmodules
和inner_repo
被上演。
Explanation according to 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.可选参数
<path>
是克隆子模块存在于超级项目中的相对位置。 If<path>
exists and is already a valid Git repository, then it is staged for commit without cloning.如果
<path>
存在并且已经是有效的 Git 存储库,则将其暂存以进行提交而不进行克隆。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.