什么是git
git是世界上最好的分布式版本控制系统
什么意思?可以看廖雪峰的git教程前面部分了解其概念
如何在本地使用git
首先,打开你的命令行,本次我使用的是Windows上的git bash,进入你的桌面 cd Desktop/

在桌面创建一个文件夹,如 git-demo-1
mkdir git-demo-1

1. git init 初始化本地仓库 .git
进入这个目录:cd git-demo-1
然后输入命令:git init
这句命令会在 git-demo-1 里创建一个 .git 目录
可以用ls -la 观察这个目录

2. git status -sb 观察当前文件状态
在 git-demo-1 目录里创建一个文件如index.html
touch index.html
运行 git status -sb 可以看到文件前面有 ??

3. git add 文件名或 git add.
?? 表示 git 不知道如何对待这个新的文件
此时要用 git add 将文件添加到「暂存区」
git add index.html(若文件较多,一个个加麻烦,可直接用git add. 一次性将所有变动加到暂存区)
然后可以再 git status -sb 观察其状态

?? 变成了 A 即告诉 git 这些文件我要加到仓库里
4. git commit -m "信息" 将文件正式提交到本地仓库(.git)
同样你可以一个个提交文件
git commit index.html -m '添加index.html'
或者一次提交所有文件
git commit . -m "添加了几个文件"
再运行 git status -sb

出现## master 说明你已经将文件上传成功了
这时你可以用 git log 看历史变动

至此,一次在本地使用 git 的过程就完成了
如果对已有文件有新的变动,我们只需要依次执行 git add xxx 和 git commit -m 'xxx' 两个命令即可
总结一下就是
1. git init 初始化本地仓库 .git
2. git add 文件名或 git add.
3. git commit -m "信息" 将文件正式提交到本地仓库(.git)
有新的变动, git add xxx 和 git commit -m 'xxx'
过程中用 git status -sb 观察当前文件状态
最后可用 git log 看历史变动
本文主要用于个人学习使用,如有侵权请联系我删除。
一些参考:
网友评论