[英]Create new git repository from an existing folder tree
I've got C/C++ project that is composed of multi-level folder tree structure, and I'd like to store it inside local git repository. 我有由多层文件夹树结构组成的C / C ++项目,我想将其存储在本地git存储库中。
using git init
I create an empty git project, and now i'd like to add the entire directory tree, with an exception of non source code files (different from the following suffixes c/c++/h/hpp/sh/py/pl/etc). 使用
git init
我创建一个空的git项目,现在我想添加整个目录树,但非源代码文件除外(与以下后缀c / c ++ / h / hpp / sh / py / pl /等等)。
Looking at other similar questions, I've used git submodule update
but it didn't add the folder tree to my new and empty git project. 看看其他类似的问题,我使用了
git submodule update
但是它没有将文件夹树添加到新的空git项目中。
moreover, I know that in order to exclude files, I should use .gitignore
file, but i'm not sure in each stage it should be created (what if the repository is already made, and i want to remove all .o files) Here are my commands, perhaps anyone can tell me what I'm doing wrong ? 而且,我知道为了排除文件,我应该使用
.gitignore
文件,但是我不确定在每个阶段都应该创建它(如果已经建立存储库,我想删除所有.o文件)这是我的命令,也许有人可以告诉我我做错了什么?
[]$ git init .
Initialized empty Git repository in /Users/myself/projects/otool/otool-ng-master/.git/
[]$ git submodule update --init --recursive
using git init I create an empty git project, and now i'd like to add the entire directory tree
使用git init我创建一个空的git项目,现在我想添加整个目录树
You have few options: 您有几种选择:
git sparse
- Checkout a specific (partial) part of your repo. git sparse
签出仓库的特定(部分)部分。 git submodule
Submodule
is a standalone git project so the code will be checked out to a new folder under the root folder and it's not part of your master branch. Submodule
是一个独立的 git项目,因此代码将检出到根文件夹下的新文件夹中,并且不属于master分支。
Your root folder will contain a submodule file and you will have to "int && update" it on every clone you make. 您的根文件夹将包含一个子模块文件,并且您必须在创建的每个克隆上“ int &&更新”它。
# Add the desired submodule ot your code base
git submodule add <url>
You must run two commands: 您必须运行两个命令:
git submodule init
to initialize your local configuration file, and 初始化本地配置文件,以及
git submodule update
to fetch all the data from that project and check out the appropriate commit listed in your superproject: 从该项目中获取所有数据,并检查超级项目中列出的相应提交:
So the full script is this: 因此,完整的脚本是这样的:
git submodule add <url>
git submodule init
git submodule update
moreover, I know that in order to exclude files
而且,我知道为了排除文件
This is a very simple task: add the desired path/file whic yoiu wish to ignore to your .gitignore
file 这是一个非常简单的任务:将想要忽略的所需路径/文件添加到您的
.gitignore
文件中
My suggestion is to do like this: 我的建议是这样做:
cd your_project_root_folder
cd your_project_root_folder
git init
git初始化
Then create a .gitignore file to ignore generated files (*.o, *.a, ...). 然后创建一个.gitignore文件以忽略生成的文件(* .o,*。a,...)。
git add .
git添加
This will add all your project files to the Git repository with the exception of the ignored ones. 这会将您的所有项目文件添加到Git存储库,但忽略的文件除外。 If files not intended for preservation are added to the repository then update your .gitignore file, then type:
如果将不打算保留的文件添加到存储库,则更新.gitignore文件,然后键入:
rm -fr .git
rm -fr .git
git init
git初始化
git add .
git添加
When you are happy of your .gitignore file, just type: 当您对.gitignore文件感到满意时,只需键入:
git commit -m "My first commit"
git commit -m“我的第一次提交”
Juste create a .gitignore
file with a line to ignore .o
files for example. Juste用行创建一个
.gitignore
文件,以忽略例如.o
文件。 Then add your folders to the index git add *
and commit. 然后将您的文件夹添加到索引
git add *
并提交。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.