How do you create a new project/repository? (如何创建新的项目/存储库?)
A git repository is simply a directory containing a special .git
directory. (git存储库只是一个包含特殊.git
目录的目录。)
This is different from "centralised" version-control systems (like subversion), where a "repository" is hosted on a remote server, which you checkout
into a "working copy" directory. (这与“集中式”版本控制系统(如Subversion)不同,在“集中式”版本控制系统中,“存储库”托管在远程服务器上,您可以将其checkout
到“工作副本”目录中。) With git, your working copy is the repository. (使用git,您的工作副本就是存储库。)
Simply run git init
in the directory which contains the files you wish to track. (只需在包含您要跟踪的文件的目录中运行git init
。)
For example, (例如,)
cd ~/code/project001/
git init
This creates a .git
(hidden) folder in the current directory. (这将在当前目录中创建一个.git
(隐藏)文件夹。)
To make a new project, run git init
with an additional argument (the name of the directory to be created): (要创建一个新项目,请使用附加参数(要创建的目录的名称)运行git init
:)
git init project002
(This is equivalent to: mkdir project002 && cd project002 && git init)
To check if the current current path is within a git repository, simply run git status
- if it's not a repository, it will report "fatal: Not a git repository" (要检查当前当前路径是否在git存储库中,只需运行git status
如果它不是存储库,它将报告“严重:不是git存储库”)
You could also list the .git
directory, and check it contains files/directories similar to the following: (您还可以列出.git
目录,并检查它是否包含类似于以下内容的文件/目录:)
$ ls .git
HEAD config hooks/ objects/
branches/ description info/ refs/
If for whatever reason you wish to "de-git" a repository (you wish to stop using git to track that project). (如果出于某种原因您希望“解散”存储库(您希望停止使用git跟踪该项目)。) Simply remove the .git
directory at the base level of the repository. (只需在存储库的基础级别上删除.git
目录。)
cd ~/code/project001/
rm -rf .git/
Caution: This will destroy all revision history, all your tags, everything git has done. (注意:这将销毁所有修订历史记录, 所有标签以及git所做的所有事情。) It will not touch the "current" files (the files you can currently see), but previous changes, deleted files and so on will be unrecoverable! (它不会触摸“当前”文件(您当前可以看到的文件),但是以前的更改,已删除的文件等将无法恢复!)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…