$ git status On branch hexo nothing to commit, working tree clean $echo 3333333333333 >> x.txt $ git status On branch hexo Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: x.txt
no changes added to commit (use "git add" and/or "git commit -a")
$ git diff x.txt warning: LF will be replaced by CRLF in x.txt. The file will have its original line endings in your working directory diff --git a/x.txt b/x.txt index 140fb9b..e63237b 100644 --- a/x.txt +++ b/x.txt @@ -1,3 +1,4 @@ aaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbb cccccccccccccccccccc@222 +3333333333333
0x02 HEAD指针
HEAD是当前分支最近一次提交的引用
1 2 3 4 5 6 7 8 9
$ cat .git/HEAD ref: refs/heads/hexo $ git checkout master Switched to branch 'master' M x.txt $ cat .git/HEAD ref: refs/heads/master
$ git log commit 1405868ee69c9b682e9caf0c0b182d297cea084e (HEAD -> master, hexo) Author: peaceSh4wn <iseonow877@sina.com> Date: Sat Feb 8 16:00:38 2020 +0800
add y.txt
commit 116d8b76b22bec10dc0826c1181002ac4930f5b1 Author: peaceSh4wn <iseonow877@sina.com> Date: Sat Feb 8 15:55:02 2020 +0800
ok
commit b4d9c9a9a72c8eaeb7bf596e050772d19cca64c8 Author: peaceSh4wn <iseonow877@sina.com> Date: Sat Feb 8 15:35:08 2020 +0800
first commit
$ git log --pretty=oneline # 单行显示 1405868ee69c9b682e9caf0c0b182d297cea084e (HEAD -> master, hexo) add y.txt 116d8b76b22bec10dc0826c1181002ac4930f5b1 ok b4d9c9a9a72c8eaeb7bf596e050772d19cca64c8 first commit
git reset 某一版本
我们使用git reset HEAD^回到当前上一个版本
1 2 3
$ git reset HEAD^ Unstaged changes after reset: M x.txt
git reset HEAD^^回到当前上两个版本
1 2 3 4 5 6 7 8 9
$ git log --pretty=oneline 282715040b9e65d9789827faa9a0110cf5d76fee (HEAD -> master) delete x.txt 6431293265114fc23433eee025e61e49273cf51c add z.txt and add string in the end of y.txt dc496fa5d34216b1538bf59e013d5e5cae332261 2 b4d9c9a9a72c8eaeb7bf596e050772d19cca64c8 first commit $ git reset HEAD^^ Unstaged changes after reset: D x.txt
git reset HEAD~100当前上100个版本
1 2 3 4 5 6 7 8
$ git reset HEAD~100 # 我们这里没有100多个版本,报错是必然的 XDD fatal: ambiguous argument 'HEAD~100': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]' $ git log --pretty=oneline dc496fa5d34216b1538bf59e013d5e5cae332261 (HEAD -> master) 2 b4d9c9a9a72c8eaeb7bf596e050772d19cca64c8 first commit
$ git reset --hard 28271 HEAD is now at 2827150 delete x.txt $ git log --pretty=oneline dc496fa5d34216b1538bf59e013d5e5cae332261 (HEAD -> master) 2 b4d9c9a9a72c8eaeb7bf596e050772d19cca64c8 first commit