我可以从 2 个断开连接的目录创建 Git 存储库吗?



我有一个 PHP Web 应用程序,我想捆绑到 GitHub 上的 Git 存储库中,但我不清楚如何,因为用户界面在 webroot 中,但出于安全目的,模型、控制器、存储等都在 webroot 之外的文件夹中。 即它看起来像:

C:/inetpub
|—App_code_directory
|—Lots_of_unwanted_directories
|—wwwroot
|—App_interface_directory
|—Lots_of_unwanted_directories

是否可以直接从两个应用程序目录构建存储库? 我是否需要将其基于 inetpub 并创建一个巨大的.gitignore文件? 这显然是一种常见的应用程序架构,但我无法以一种能够产生答案的方式表达我的 Web 搜索。

更新:我在下面添加了一个答案,显示了我是如何做到的,这是一个比我最初设想的更有效的.gitignore文件。

是的,您可以从两个目录中构建一个存储库,并排除Lots_of_unwanted_directories。在此示例中,您将

  1. cd c:inetpub
  2. echo "Lots_of_unwanted_directories" > .gitignore
  3. git init .
  4. git add remote origin <your github url here>
  5. git commit . -m "Initial commit"
  6. git push origin master

但是等等。仅仅因为它是可能的并不意味着它是一个好主意。您可能希望先将源代码移动到其他工作区文件夹中,并具有发布到 c:\inetpub 的构建文件或任务。

在环顾四周并找到如何.gitignore除选定元素之外的所有内容后,我决定从我的 inetpub 目录中创建一个存储库,并只包含我需要的部分。 下面是生成的.gitignore的外观。

# Start by excluding everything
*
# Add back in all subdirectories, but not their contents
!/*
# Remove any files within the base directory
*.*
# Add the code base folder contents
!PROJECT_base/**
# Add back in the wwwroot subdirectory
!wwwroot/*
# Remove any files in the wwwroot subdirectory
wwwroot/*.*
# Add the interface folder and contents
!wwwroot/PROJECT/**
# Remove any files from the storage folders
PROJECT_base/storage/uploads/*.*
PROJECT_base/storage/downloads/*.*
wwwroot/PROJECT/downloads/*.*
# Add the stub files back
!**/stub.txt

最新更新