git入门

git 是分散式版本控制系统,大部分操作可以在本地进行。

而svn 是集中式版本控制系统,依赖网络。

输入git,确认是否已安装。

如果没有,就装一个。

传送门:https://git-scm.com/downloads

然后设置用户名和账号

git config --global user.name "Your Name"
git config --global user.email "email@example.com"

--global 代表全局使用

 

1、git init

使用git,首先需要建立仓库。

git init 可以在当前目录中建立新的仓库,成功的话,会自动新建.git这个目录,.git这个目录默认是隐藏的。

提示Initialized empty Git repository in 路径,代表这是一个新的目录

当前目录不是空的也ok。

 

2、git add

git add [文件名a] 添加文件a到缓存

git add . 添加当前目录的所有文件到缓存

成功则不会返回任何信息。

 

3、git commit 

git commit -m '提交的信息' 提交文件到仓库,-m 是本次提交的说明

成功则会返回提交文件的信息

git commit -v 提交时显示所有的diff信息(编辑器中),从而知道本次提交做了哪些更改,如

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Your branch is up-to-date with 'origin/master'.
#
# Changes to be committed:
# new file: test.html

# ------------------------ >8 ------------------------
# Do not touch the line above.
# Everything below will be removed.
diff --git a/test.html b/test.html
new file mode 100644
index 0000000..30d74d2
--- /dev/null
+++ b/test.html
@@ -0,0 +1 @@
+test

 

总结:一般流程使用git init > git add . > git commit -m ' 提交的信息'就可以了。

如果是需要提交到远程,则需要commit后再使用git push。

如果是多人共同使用,则最好养成git pull的习惯再push。

 进一步拓展请看:

廖雪峰的git 课程:https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000

Git官方教程:https://git-scm.com/doc

posted @ 2018-03-31 00:22  颤抖的艾可  阅读(90)  评论(0)    收藏  举报