码迷,mamicode.com
首页 > 其他好文 > 详细

Git(一)——初识

时间:2016-12-10 00:52:07      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:等等   git init   tween   wiki   版本控制   try   基于   mod   清单   

Git(一)——初识

1. 综述

想必都听过 Git 的鼎鼎大名,传说是某大神花了两周写的,因为之前一直支援他开源社区的收费 CVS 厂商收回了帮助…

Git 是一个流行的版本控制系统,GitHub 就是一个基于 Git 的版本托管系统,上面有众多大家分享的代码。

2. 入门的几个命令

当然首先要下载安装 Git,这里不赘述。

要在本地建立一个 repository,运行:

git init

即在本文件夹建立一个本地的 repository。还可以在本文件夹内运行:

git init myRepositoryName

生成一个 myRepositoryName 子目录,在这个子目录里建立了一个本地的 repository。

 

不过更常用的是把远程的仓库下载到本地,这将使用一个有名的命令,以远程仓库的地址在 https://github.com/TryGhost/Ghost.git 为例:

git clone https://github.com/TryGhost/Ghost.git

即将远程的仓库下载到本地,这时将在本地出现一个此仓库的文件夹。

 

增加了文件之后,使用

git add <filename>

将文件加入 Git 中,以便进一步 commit 和 push,否则文件就不会被 Git 记录,在 repository 的根目录有时会有一个叫 .gitignore 的文件,里面就是希望被忽略、不加入 Git 的文件的名字。将文件加入 Git 也可以

git add .

将所有文件加入 Git 中,当然不包括 .gitignore 中的文件。

 

之后,使用

git commit -m "this is the message about this commit"

提交到本地仓库。也可以使用

git commit -a -m "this is the message about this commit"

来提交,它的效果相当于它之前的两个命令之和,即

git add .
git commit -m "this is the message about this commit"

 

最后,把本地的 repository 提交到远程,使用

git push

即可。

 

另外,在任何时候,可以使用

git status

查询当前 repository 的信息,如有没有文件需要 add,有没有 modify 需要 commit 等等。

 

3. 更多

各常用的作用(有图解):

What are the differences between “git commit” and “git push”?

阮一峰的网络日志:常用 Git 命令清单

 

 

Git(一)——初识

标签:等等   git init   tween   wiki   版本控制   try   基于   mod   清单   

原文地址:http://www.cnblogs.com/yongheng20/p/6151976.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!