$ git diff readme.txt diff --git a/readme.txt b/readme.txt index e69de29..5367626 100644 --- a/readme.txt +++ b/readme.txt @@ -0,0 +1,2 @@ +Git is a distributed version control system. +Git is a free software. warning: LF will be replaced by CRLF in readme.txt. The file will have its original line endings in your working directory.
一般来说,修改文件之后在add之前马上使用git diff才能看到区别
add提交之后再使用diff就不能看到区别了
add之前使用git status看到的是修改文件是红色的
add之后使用git status看到的是修改文件是绿色的
commit之后再使用git status就看不到变化了
使用git log --pretty=oneline查看修改情况
1 2 3 4 5 6 7 8 9 10
$ git log --pretty=oneline 9e86558600d190136a1b109dff14f70587b0c11a modify tow line afd2594462a539056a88b978f1062d02f54e3bfb add a line 86905b5f5584d902eb78fd1d589bc8fbddccfd66 remove distribute 47a40c4bb05c2ac81c56148e0135aef78defc219 fisrt modify f8f397cb4868fd77a08cffb8e6b277fe8f0eee5c remove distirbute 432d801fe7c3720a8ca5a4b52eb83ba7272a5760 Change the discription e7facd5759491dcefdb73b4b2cd004d71fd72645 Change the discription 3ea98a88c081d219804cb661a46d3349b1bd44df wrote a readme file
使用命令git reset --hard HEAD^返回上一个版本
1 2
$ git reset --hard HEAD^ HEAD is now at afd2594 add a line
Tony@Tony-PC MINGW64 /e/gitrepository/learngit (master) $ git status On branch master Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) #modified: readme.txt还存在 deleted: readme modified: readme.txt modified: test.txt
no changes added to commit (use "git add" and/or "git commit -a")
Tony@Tony-PC MINGW64 /e/gitrepository/learngit (master) $ git status On branch master Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) #使用git checkout -- readme.txt, modified: readme.txt记录就消失了 deleted: readme modified: test.txt
no changes added to commit (use "git add" and/or "git commit -a")
Tony@Tony-PC MINGW64 /e/gitrepository/learngit (master) $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) #修改已经提交了 modified: readme.txt
Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory)
deleted: readme modified: test.txt
#用命令git reset HEAD file可以把提交到暂存区的修改撤销掉(unstage),重新放回工作区 Tony@Tony-PC MINGW64 /e/gitrepository/learngit (master) $ git reset HEAD readme.txt Unstaged changes after reset: D readme M readme.txt M test.txt
#提交到缓存区的修改已经被撤销了 Tony@Tony-PC MINGW64 /e/gitrepository/learngit (master) $ git status On branch master Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory)
Tony@Tony-PC MINGW64 /e/gitrepository/learngit (master) $ git push -u origin master The authenticity of host 'github.com (192.30.253.113)' can't be established. RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8. Are you sure you want to continue connecting (yes/no)? y Please type 'yes' or 'no': yes Warning: Permanently added 'github.com,192.30.253.113' (RSA) to the list of known hosts. Counting objects: 38, done. Delta compression using up to 8 threads. Compressing objects: 100% (35/35), done. Writing objects: 100% (38/38), 3.22 KiB | 0 bytes/s, done. Total 38 (delta 11), reused 0 (delta 0) To git@github.com:TonyDandelion/learngit.git * [new branch] master -> master Branch master set up to track remote branch master from origin.
$ git checkout -b dev Switched to a new branch 'dev'
git checkout命令加上-b参数表示创建并切换,相当于以下两条命令:
1 2 3
$ git branch dev $ git checkout dev Switched to branch 'dev'
2、使用git branch来查看当前的分支
1 2 3
$ git branch * dev master
3、在当前分支下修改文本文件
1 2 3 4
Tony@Tony-PC MINGW64 /e/gitrepository/gitskills (master) $ cat README.md # gitskills Creating a new branch is quick
4、操作完成,切回master。
1 2 3 4 5 6 7 8 9
Tony@Tony-PC MINGW64 /e/gitrepository/gitskills (dev) $ git checkout master Switched to branch 'master' Your branch is up-to-date with 'origin/master'.
Tony@Tony-PC MINGW64 /e/gitrepository/gitskills (master) $ git branch dev * master