$ git config --global user.name "Your Name" $ git config --global user.email "email@example.com"
md F:\\learngit
$ cd f:/learngit
$ git init
$ touch readme.txt
$ 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")
$ git add readme.txt
$ git commit -m "[* update readme.txt file]"
1 file changed,1insertion(+),1deletion(-)
[+ 增加了什么文件]
[- 删除了什么文件]
[* 编辑了什么文件]
$ git log commit 542e3f3649fb5e0cc7b1a94d8576de8d8ffdf054 (HEAD -> master) Author: Your Name <xxxx@126.com> Date: Tue Apr 9 17:12:30 2019 +0800 [* update readme.txt file ] commit 6f8a5e1d807bd01769086c90e7cdc57630b52fb0 Author: Your Name <xxx@126.com> Date: Tue Apr 9 16:55:13 2019 +0800 [+ 添加readme文件]
$ git reflog c86b138 (HEAD -> master) HEAD@{0}: reset: moving to c86b1386936499665d85c287447516a0ea9b4752 542e3f3 HEAD@{1}: reset: moving to HEAD^ c86b138 (HEAD -> master) HEAD@{2}: commit: [* updte readme.txt] 542e3f3 HEAD@{3}: reset: moving to 542e3f3649fb5e0cc7b1a94d8576de8d8ffdf054 6f8a5e1 HEAD@{4}: reset: moving to HEAD^ 542e3f3 HEAD@{5}: commit: [* update readme.txt file ] 6f8a5e1 HEAD@{6}: commit (initial): [+ 添加readme文件]
# git 中代表当前版本的是HEAD 上一个版本是HEAD^ 上两个版本就是HEAD^^ $ git reset --hard HEAD^ HEAD is now at 6f8a5e1 [+ 添加readme文件]
# 在add后 git reset HEAD file # HEAD 指最新版本 git checkout -- file # 丢掉工作区的代码
# 创建一个 test.txt的文件 $ touch test.txt # 将 test.txt 文件 添加到工作区 $ git add test.txt # 将 test.txt 文件 添加到版本库 $ git commit -m‘[+ add test.txt file]‘ # 直接删除文件管理器中的 test.txt 文件 $ rm test.txt # 删除版本库中的 test.txt 文件 $ git rm test.txt # 提交到版本库中 $ git commit -m‘[- delete test.txt file]‘
# 创建一个 test.txt的文件 $ touch test.txt # 将 test.txt 文件 添加到工作区 $ git add test.txt # 将 test.txt 文件 添加到版本库 $ git commit -m‘[+add test.txt file]‘ # 直接删除文件管理器中的 test.txt 文件 $ rm test.txt # 恢复 test.txt $ git checkout -- test.txt
原文:https://www.cnblogs.com/xinjie123/p/10911880.html