前言:
不要一开始接触就要弄懂git的原理,我们先从基本操作中体会,用着用着就会知道其中的原理了。本篇博客讲述的是git在本地库的用法。
先运用git在本地创建一个库:

输入git init指令,进行本地库初始化:

在文件夹中创建几个文件,输入git status -sb 查看文件状态 会出现??是吧。这是问我们要对这些文件做什么。

使用 git add 将文件添加到「暂存区」
你可以一个一个地 add
git add index.html
git add css/style.css
你也可以一次性 add
git add . 意思是把当前目录(.表示当前目录)里面的变动都加到「暂存区」

再次运行 git status -sb,可以看到 ?? 变成了 A

使用 git commit -m "信息" 将你 add 过的内容「正式提交」到本地仓库(.git就是本地仓库),并添加一些注释信息,方便日后查阅
你可以一个一个地 commit
git commit index.html -m '添加index.html'
git commit css/style.css -m "添加 css/style.css"
你也可以一次性 commit
git commit . -m "添加了几个文件"

再再次运行 git status -sb,发现没有文件变动了,这是因为文件的变动已经记录在仓库里了。

这时你使用 git log 就可以看到历史上的变动:

以上就是git init /git add/git commit -m的基本用法
网友评论