简体   繁体   English

git 存储库中子文件夹中的 Commit.git 文件夹

[英]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/.gitgit 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 中具有远程的现有本地存储库中实现了预期的结果:

  • create folder for inner repository in parent repository在父存储库中为内部存储库创建文件夹
  • copy some files to inner_repo将一些文件复制到inner_repo
  • initialize inner repository and commit the files (inside inner_repo run git init and git commit -am 'initial' )初始化内部存储库并提交文件(在inner_repo内部运行git initgit commit -am 'initial'
  • go to parent repo: cd.. . go 到父仓库: cd..
  • critical step: git submodule add./inner_repo./inner_repo关键步骤: git submodule add./inner_repo./inner_repo

After that .gitmodules and inner_repo were staged.之后.gitmodulesinner_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.

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