简体   繁体   English

从现有的文件夹树创建新的git存储库

[英]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: 您有几种选择:

  1. submodule - a standalone git project inside your root folder 子模块-根文件夹中的独立git项目
  2. git sparse - Checkout a specific (partial) part of your repo. git sparse签出仓库的特定(部分)部分。
  3. Checkout a specific folder/path 签出特定的文件夹/路径

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.

相关问题 如何从现有git存储库中的文件夹创建新的git存储库? - How do I create a new git repository from a folder in an existing git repository? 如何从现有的git存储库中创建新的git存储库,第2部分 - how to create a new git repository from an existing one, part 2 如何从现有的git存储库创建一个新的git存储库 - how to create a new git repository from an existing one 从现有的本地分支创建一个新的git存储库 - Create a new git repository from a existing local branch 从本地计算机上的现有文件夹创建 git 存储库,就好像它是从远程存储库克隆的一样 - Create a git repository from existing folder on local computer as if it's were cloned from remote repository Git - 为目录中的每个文件夹创建一个新的存储库 - Git - Create a new repository for each folder in a directory 如何从 git 存储库中现有分支中的现有文件夹创建分支? - How do i create a branch from an existing folder in an existing branch in a git repository? 如何从现有存储库创建新的 git 存储库,仅选择存储库中的特定文件夹? - How to create a new git repository from an existing repository, selecting only specific folders in the repo? 从现有库创建一个新的git库 - Creating a new git repository from an existing one git 从现有存储库初始化新 - git init new from existing repository
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM