Git

查看当前版本

$ git --version

设置全局用户名 

$ git config --global user.name "Eric"

设置全局邮箱

$ git config --global user.email "`123456@qq.com"

查看所有信息

$ git config --list

退出

Q

清空

clear

查看根目录

pwd

进入仓库目录

$ cd mygit

初始化

$ git init
Initialized empty Git repository in F:/mygit/.git/

添加到版本库

$ git add hello.txt

.和*都是所有文件

提交文件(add并非提交 -m设置提交信息)

$ git commit -m "add file hello.txt"

[master (root-commit) 3d4e2de] add file hello.txt
1 file changed, 1 insertion(+)
create mode 100644 hello.txt

查看日志

$ git log
commit 3d4e2de570d40a4dfe47436bce70a36878c364af (HEAD -> master)  -- 版本号
Author: Eric <542932873@qq.com>
Date: Tue Dec 11 09:42:31 2018 +0800

add file hello.txt --提交说明

再次修改之后提交的信息

$ git commit -m "add file hello.txt"
[master d1450fb] add file hello.txt
1 file changed, 3 insertions(+), 1 deletion(-)

再次查看日志

commit fc50fde9c4126b6d32a1bcf2590e8c263dd982b8 (HEAD -> master)
Author: Eric <542932873@qq.com>
Date: Tue Dec 11 10:19:37 2018 +0800

sumit file

commit d1450fbdfc36275f11eca36c96c1a11f7a6b7ffb
Author: Eric <542932873@qq.com>
Date: Tue Dec 11 09:48:47 2018 +0800

add file hello.txt

commit 3d4e2de570d40a4dfe47436bce70a36878c364af
Author: Eric <542932873@qq.com>
Date: Tue Dec 11 09:42:31 2018 +0800

add file hello.txt

查看状态

$ git status

add之后不提交  (modified表示add没有提交的文件)

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

modified: hello.txt

比较本地和缓存区不同 (保存未add)

$ git diff hello.txt
diff --git a/hello.txt b/hello.txt
index 5119cdd..be23755 100644
--- a/hello.txt
+++ b/hello.txt
@@ -1,4 +1,3 @@
aaaa
bbbb
ccccc
-4444
No newline at end of file

回退版本

(--mixed默认 工作区不受影响 缓存和版本修改)

(HEAD当前版本 ^ 上一个版本 可以多个)

$ git reset --mixed HEAD^

$ git reset --head +版本号 

(回退所有)

原文地址:https://www.cnblogs.com/ssjf/p/10100348.html