常用的git命令

介绍git原理的不错的文章: git from inside out

  1. git log —pretty=oneline
  2. git log -1
  3. git rev-parse —git-dir #show the .git folder name
  4. git add . git add filename git add all git add . -A
  5. git commit -s
  6. git commit -m “msg”
  7. git commit —amend # add the current file to the previous change list
  8. git push
  9. git bisect 是用二分法协助RD查找是哪笔check-in导致的错误的,请参考
  10. git diff 文件格式说明,link
  11. git diff HEAD — readme.txt
  12. git reset —hard HEAD^ 用remote端最新code盖掉index区域的改动(已经add到index的改动)
  13. git reset —hard 1094a 指定回到某个版本
  14. git cherry-pick
  15. git reflog 查找使用过的git command

    Mac01:BlueShell wnnwoo$ git reflog
    894474c (HEAD -> master) HEAD@{0}: reset: moving to HEAD^
    fcdea80 (origin/master) HEAD@{1}: commit: fix build error
    894474c (HEAD -> master) HEAD@{2}: commit: update basic operation
    94e2258 HEAD@{3}: commit: Run the scheme testing
    f305bac HEAD@{4}: commit: add generics test code
    4acfba7 HEAD@{5}: commit: Add error handle

  16. git checkout — readme.txt 丢弃工作区的改动
  17. git reset HEAD readme.txt 暂存区的修改回退到工作区
  18. git diff > abc.diff
  19. git apply abc.diff

control + r # search the history command