简体   繁体   English

如何将现有项目导入Git?

[英]How to import an existing project to Git?

I started a coding project, which has expanded in size and I want to use Git for version control. 我开始了一个编码项目,该项目的规模有所扩大,我想使用Git进行版本控制。 If that matters, the project is combination of web infrastructure written in HTML/CSS/PHP and server infrastructure written in C. 如果这很重要,则该项目是用HTML / CSS / PHP编写的Web基础结构和用C编写的服务器基础结构的组合。

I currently work in the following way: I perform changes in my development directory: /var/www/dev . 我目前的工作方式如下:在开发目录/var/www/dev执行更改。 Once I am satisfied I manually move the changed files to the live directory: /var/www/stable . 满意后,我将更改后的文件手动移动到活动目录: /var/www/stable Both stable and dev are currently the same, but are web-accessible through different domains: foo.com and dev.foo.com 目前稳定版和开发版都相同,但是可以通过不同的域通过Web访问:foo.com和dev.foo.com

I have learned the basics of Git and I am familiar with the commands, but I can`t figure out how to migrate the project, although reading several questions on Stackoverflow. 我已经学习了Git的基础知识,并且熟悉这些命令,但是尽管阅读了关于Stackoverflow的几个问题,但是我无法弄清楚如何迁移项目。 I want to maintain a dev version accessible at dev.foo.com. 我想维护一个可在dev.foo.com上访问的dev版本。 Should I do it that way: 我应该这样做吗?

  1. Open /var/www/master and create the repo with: git init , git add . 打开/ var / www / master并使用以下命令创建存储库: git initgit add . and git commit . git commit
  2. Open /var/www/dev and pull the repo with: git pull file:////var/www/stable . 打开/ var / www / dev并使用以下命令拉回购: git pull file:////var/www/stable .

Once that is done, I should be able to work in my dev environment and have branches in the dev repo, but how will I push the changes to the stable version? 完成之后,我应该能够在我的开发环境中工作并在开发仓库中拥有分支,但是如何将更改推送到稳定版本? Is there a better way to organize that process? 是否有更好的方法来组织该过程?

You may create a bare repo that you push your work to and fetch changes to the stable directory. 您可以创建一个裸仓库,将您的工作推送到该仓库中,并获取对稳定目录的更改。 Make a clone in the stable directory and another clone where you do the actual work. 在稳定目录中创建一个克隆,在实际工作中创建另一个克隆。

In a directory where you keep the bare repo 在保存裸仓库的目录中

git init --bare

In the stable directory 在稳定目录中

git init
git add .
git commit -m "first commit"
git remote add origin <path to bare repo>
git push origin master

Create a clone where you do the work 创建一个工作所在的克隆

git clone <path to bare repo> dev
cd dev
git fetch
...do some work ...
git add .
git commit -m "fix for...."
git push origin master

When you are sattisfied with the your work, go back to the stable directory 当您对工作满意后,返回稳定目录

git pull origin

This is one way of doing this, you may need to change this workflow so suite your needs. 这是执行此操作的一种方式,您可能需要更改此工作流程,以适应您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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