- It is good practice to always review our changes before saving them. We do this using git diff. This shows us the differences between the current state of the file and the most recently saved version:
git diff
- Git does not track directories on their own, only files within them.
- See the differences between older commits we can use git diff
# 最近c(diǎn)ommit和當(dāng)前的區(qū)別
git diff HEAD
# 最近c(diǎn)ommit的往前一次的commit和當(dāng)前的區(qū)別
git diff HEAD~1 mars.txt
# 最近c(diǎn)ommit的往前兩次次的commit和當(dāng)前的區(qū)別
git diff HEAD~2 mars.txt
- shows us what changes we made at an older commit as well as the commit message, rather than the differences between a commit and our working directory
# 最近c(diǎn)ommit做了哪些事
git show HEAD
- We can also refer to commits using those long strings of digits and letters that git log displays
git diff f22b25e3233b4645dabd0d81e651fe074bd8e73b mars.txt
# 其實(shí)用前幾位就夠了
git diff f22b25e mars.txt
- restore older versions of things
# 假設(shè)只是修改了文件 沒有add 沒有commit
# 測(cè)試了一下 發(fā)現(xiàn)add之后也可以restore
git status
# 將文件返回到最近一次commit 當(dāng)然也可以通過(guò)別的HEAD或者log里的ID來(lái)返回更靠前的commit
# 不要忘記文件名 不然整個(gè)都會(huì)被restore
git checkout HEAD mars.txt
git revert will create a new commit that reverses Jennifer’s erroneous commit.
git checkout returns the files within the local repository to a previous state without create a new commitTell Git to ignore files I don’t want to track
http://swcarpentry.github.io/git-novice/06-ignore/index.htmlthe Collaborator can use git fetch origin master to get the remote changes into the local repository, but without merging them. Then by running git diff master origin/master the Collaborator will see the changes output in the terminal.
Conflict
http://swcarpentry.github.io/git-novice/09-conflict/index.html