将现有的源代码文件夹添加到 Git

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6913519/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 11:28:56  来源:igfitidea点击:

Adding existing source code folder to Git

git

提问by RKh

I am new to Git. I want to add an existing source code folder to Git, but based on the little documentation that I read, I guess files must be a Tar ball or tar.gz archive. I am also not finding a way to add an entire existing folder.

我是 Git 的新手。我想将现有的源代码文件夹添加到 Git,但根据我阅读的小文档,我猜文件必须是 Tar ball 或 tar.gz 存档。我也没有找到添加整个现有文件夹的方法。

Is it not possible to add non-compressed files to Git repository along with the folder that contains the files?

是否无法将非压缩文件与包含文件的文件夹一起添加到 Git 存储库?

回答by Bushibytes

It depends what you mean by adding a directory to a Git repository.

这取决于您将目录添加到 Git 存储库的含义。

I get the feeling that you mean that you want to create a new project using an existing directory. In which case, you would need to go inside your directory and use git init. Here a quick guideI just found.

我感觉您的意思是要使用现有目录创建一个新项目。在这种情况下,您需要进入您的目录并使用git init。这是我刚刚找到的快速指南

However, if you mean that you already have a Git project and wish to add a directory - the answer is simply to use git addpath

但是,如果您的意思是您已经有一个 Git 项目并希望添加一个目录 - 答案就是使用git add path

Let us know if you need more information (such as setting up a remote, or using github.)

如果您需要更多信息,请告诉我们(例如设置遥控器或使用 github。)

回答by Tamás Szelei

No, you don't need it compressed. Git operates on the filesystem.

不,你不需要压缩它。Git 在文件系统上运行。

If you want to create a new repository from existing source, just cd into that directory and type: git init.

如果你想从现有源的新库,只是cd到该目录,类型:git init

Add the current state of files to the index with git add .(note the trailing dot)

将文件的当前状态添加到索引中git add .(注意尾随点)

If you want to add existing code to an existing repository, you also need git add(and probably copy the files to where you repo is).

如果要将现有代码添加到现有存储库,您还需要git add(并且可能将文件复制到存储库所在的位置)。

I suggest to take some time to actually learn and understand git before using, because doing so will save you a lot of trouble.

我建议在使用之前花一些时间来真正学习和理解git,因为这样做会为您省去很多麻烦。

回答by Prajwal W

In case if you are using Gitkraken then it is the most simplest method.

如果您使用 Gitkraken,那么它是最简单的方法。

Steps:

脚步:

  1. on Gitkraken- File -> Init Repo.
  2. Fill in the details.
  3. Click on Create and Init repo. and there you go your existing source code is uploaded on your github under you mentioned or created repo.
  1. 在 Gitkraken-文件 -> Init Repo 上。
  2. 填写详细信息。
  3. 单击创建和初始化存储库。然后您将现有的源代码上传到您提到或创建的 repo 下的 github 上。