git学习01- 下载安装&初始化库&提交

时间:2022-02-02 08:01:00

1、windows下安装git,git官网下载安装包安装

2、本地创建一个目录,在目录下创建1个文本 readme.txt

3、cmd进入到该目录,执行git init,初始化git仓库

4、添加文件到git仓库中

  ① git add reame.txt      将本地分支的该文件提交到git的暂存区

  ② git commint -m "message"    将git的暂存区的所有文件提交至master分支

***

本地的git目录为工作区;

隐藏的.git目录下是版本库,版本库中包含一个暂存区,以及git自动创建的master分支

如下:

git学习01- 下载安装&初始化库&提交

5、修改readme.txt

6、在cmd下执行git status查看仓库状态,可知晓该文件被修改,但还没有提交

D:\learn\git_test>git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   readme.txt

no changes added to commit (use "git add" and/or "git commit -a")

7、可使用git diff readme.txt修改前后的差别

D:\learn\git_test>git diff readme.txt
diff --git a/readme.txt b/readme.txt
index f362e74..f137c15
--- a/readme.txt
+++ b/readme.txt
@@ -, +, @@
-Git is a version control system
+Git is a distributed version control system
 Git is a free software

8、使用add命令,添加待提交的文件,提交前、提交后使用git status命令查看,如下

D:\learn\git_test>git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   readme.txt

no changes added to commit (use "git add" and/or "git commit -a")

D:\learn\git_test>git add readme.txt

D:\learn\git_test>git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   readme.txt

D:\learn\git_test>git commit -m "add a distributed word"
[master a915e7b] add a distributed word
  file changed,  insertion(+),  deletion(-)

D:\learn\git_test>git status
On branch master
nothing to commit, working tree clean