初始化命令为 git init
首先新建一个文件夹作为仓库文件夹
R@R MINGW64 ~
$ mkdir gitlearn
R@R MINGW64 ~
$ cd gitlearn
R@R MINGW64 ~/gitlearn
$ git init
Initialized empty Git repository in C:/Users/R/gitlearn/.git/
初始化成功后,会在目录下生成**.git**文件
命令为 git status
$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
显示了没有可提交的内容,因此我们创建一个文件为提交做准备
R@R MINGW64 ~/gitlearn (master)
$ touch README.md
R@R MINGW64 ~/gitlearn (master)
$ git status
On branch master
No commits yet
Untracked files:
(use "git add ..." to include in what will be committed)
README.md
nothing added to commit but untracked files present (use "git add" to track)
会提示变动的文件,并且显示我们没有将其添加到暂存区
命令git add
R@R MINGW64 ~/gitlearn (master)
$ git add README.md
R@R MINGW64 ~/gitlearn (master)
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached ..." to unstage)
new file: README.md
可以看到状态变成了待提交
命令git commit
R@R MINGW64 ~/gitlearn (master)
$ git commit -m "my first commit"
[master (root-commit) d07f69b] my first commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 README.md
-m后的信息是描述信息,用来描述提交记录,如果想写多一点的话,直接执行git commit不加后面的**-m**,会弹出编辑器,用来添加长描述
通常
在编辑器中记述提交信息的格式如下。
● 第一行:用一行文字简述提交的更改内容
● 第二行:空行
● 第三行以后:记述更改的原因和详细内容
如果不想提交了则
将提交信息留空并直接关闭编
辑器,随后提交就会被中止
查看提交后的状态
R@R MINGW64 ~/gitlearn (master)
$ git status
On branch master
nothing to commit, working tree clean
命令为
git log查看以往的日志
git log --pretty=short只显示提交信息的第一行
git log 目录名/文件名查看特定目录或者文件的日志
git log -p查看提交日志和提交前后的差别
R@R MINGW64 ~/gitlearn (master)
$ git log
commit d07f69bc0e3f3d4268bd377f9585e80718756c62 (HEAD -> master)
Author: RR <[email protected]>
Date: Sat Oct 22 18:15:55 2022 +0800
my first commit
R@R MINGW64 ~/gitlearn (master)
$ git log --pretty=short
commit d07f69bc0e3f3d4268bd377f9585e80718756c62 (HEAD -> master)
Author: RR <[email protected]>
my first commit
R@R MINGW64 ~/gitlearn (master)
$ git log README.md
commit d07f69bc0e3f3d4268bd377f9585e80718756c62 (HEAD -> master)
Author: RR <[email protected]>
Date: Sat Oct 22 18:15:55 2022 +0800
my first commit
R@R MINGW64 ~/gitlearn (master)
$ git log -p
commit d07f69bc0e3f3d4268bd377f9585e80718756c62 (HEAD -> master)
Author: RR <97416032@qq.com>
Date: Sat Oct 22 18:15:55 2022 +0800
my first commit
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..e69de29
因为没更改所以没差别,下一次将记录查看差别
R@R MINGW64 ~/gitlearn (master)
$ git log -p README.md
commit d07f69bc0e3f3d4268bd377f9585e80718756c62 (HEAD -> master)
Author: RR <97416032@qq.com>
Date: Sat Oct 22 18:15:55 2022 +0800
my first commit
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..e69de29