【问题标题】:Copy existing project into git for version control将现有项目复制到 git 中以进行版本控制
【发布时间】:2024-05-01 22:00:03
【问题描述】:

大家好。

请帮助我。我将在整体使用版本管理的大公司找到工作。我盯着学习 git。我想将我的项目复制到新创建的 git 存储库中以启动版本控制。我的项目结构是:

.
├── pom.xml
├── src
│   ├── main
│   │   ├── java
│   │   │   ├── demidov
│   │   │   │   └── pkg
│   │   │   │       ├── domain
│   │   │   │       │   ├── ComputerMaintenanceEvent.java
│   │   │   │       │   ├── SoftwareDevelopmentEvent.java
│   │   │   │       │   ├── TheUser.java
│   │   │   │       │   ├── UserContactInfo.java
│   │   │   │       │   └── UserEvents.java
│   │   │   │       ├── persistence
│   │   │   │       │   ├── AppOut.java
│   │   │   │       │   ├── UserSecurityService.java
│   │   │   │       │   ├── WebContentDAOIF.java
│   │   │   │       │   └── WebContentDAOImpl.java
│   │   │   │       ├── service
│   │   │   │       └── web
│   │   │   │           ├── LoginController.java
│   │   │   │           └── RenderSiteController.java
│   │   │   ├── userEvents.hbm.xml
│   │   │   └── user.hbm.xml
│   │   ├── resources
│   │   └── webapp
│   │       ├── resources
│   │       │   ├── css
│   │       │   │   ├── bootstrap.css
│   │       │   │   ├── bootstrap.min.css
│   │       │   │   ├── bootstrap-responsive.css
│   │       │   │   └── bootstrap-responsive.min.css
│   │       │   ├── img
│   │       │   │   ├── background_java.jpg
│   │       │   │   ├── glyphicons-halflings.png
│   │       │   │   └── glyphicons-halflings-white.png
│   │       │   └── js
│   │       │       ├── bootstrap.js
│   │       │       ├── bootstrap.min.js
│   │       │       ├── jquery-1.10.2.min.js
│   │       │       ├── jquery.nav.js
│   │       │       └── jquery.scrollTo.js
│   │       └── WEB-INF
│   │           ├── spring
│   │           │   ├── security-context.xml
│   │           │   ├── servletConfig
│   │           │   │   └── servlet-context.xml
│   │           │   └── spring-context.xml
│   │           ├── view
│   │           │   ├── home.jsp
│   │           │   └── login.jsp
│   │           └── web.xml
│   └── test
│       ├── java
│       └── resources
└── target
    ├── classes
    │   ├── demidov
    │   │   └── pkg
    │   │       ├── domain
    │   │       │   ├── ComputerMaintenanceEvent.class
    │   │       │   ├── SoftwareDevelopmentEvent.class
    │   │       │   ├── TheUser.class
    │   │       │   ├── UserContactInfo.class
    │   │       │   └── UserEvents.class
    │   │       ├── persistence
    │   │       │   ├── AppOut.class
    │   │       │   ├── UserSecurityService.class
    │   │       │   ├── WebContentDAOIF.class
    │   │       │   └── WebContentDAOImpl.class
    │   │       ├── service
    │   │       └── web
    │   │           ├── LoginController.class
    │   │           └── RenderSiteController.class
    │   ├── userEvents.hbm.xml
    │   └── user.hbm.xml
    ├── m2e-wtp
    │   └── web-resources
    │       └── META-INF
    │           ├── MANIFEST.MF
    │           └── maven
    │               └── demidov.pkg
    │                   └── webcontent
    │                       ├── pom.properties
    │                       └── pom.xml
    └── test-classes

如何将它添加到 git 中以开始我的版本管理? 向您致以最诚挚的谢意。

【问题讨论】:

  • 为什么你的项目结构很重要?我的意思是你想用 git 来实现你的项目吗? git init && git add . 还不够吗? git如何入手可以参考git-scm.com/book
  • 我希望如此。由于我几个小时前才开始学习 git 并尝试了 git add,但是从 git.scm.com 的文档中它会单独复制每个文件,我想通过一个命令将整个结构复制到 git 存储库。我这样做: git add /home/vadim/Desktop/webcontent/* 其中 webcontent 是我的项目所在的文件夹,* 我的意思是复制所有内部 webcontent。在我得到 /home/vadim/Desktop/webcontent/pom.xml' 在存储库之外。有什么问题??
  • 尝试从项目根目录git add -A添加当前目录和所有子目录下的所有文件。
  • 它说:致命:不是 git 存储库(或任何父目录):.git 在此之前我创建了 git 目录并做了 git init。它说:在 /home/vadim/Documents/git/.git/ 中初始化空的 Git 存储库

标签: git version-control version


【解决方案1】:

从您的个人项目的根目录中,您是否运行了git init,然后运行了git add .

【讨论】: