草 稿

Git 常用命令

来自廖雪峰教程:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000

  1. git add filename

  2. git commit -m'comment'

  3. git push

  4. git status (check status)

  5. git diff filename

  6. git log (show logs)

  7. git reset --hard HEAD^ (^ means last, ^^ means last of last, HEAD means current)

  8. git reset --hard ID#

  9. git checkout -- filename (乱改了工作区的文件不要了,就是让这个文件回到最近一次git commit或git add时的状态。)

  10. git reset HEAD file (把暂存区的修改放弃掉,使用工作区的最新版本)

  11. git rm + git commit (在版本库中删除文件)

  12. git remote add origin git@server-name:path/repo-name.git (关联远程库)

  13. git push origin master (将本地提交push 到远程库)

  14. git clone git@github.com: 路径 ( clone 远程库到本地)

  15. git checkout -b dev (创建dev 分支并切换到dev)

  16. git branch (查看分支)

  17. git branch name (创建分支)

  18. git checkout name (切换分支)

  19. git merge name (合并某分支到当前分支)

  20. git branch -d name (删除分支)

  21. git log --graph --pretty=oneline --abbrev-commit (仅展示commit信息的图形化分支)

  22. git merge --no-ff -m "merge with no-ff" dev (用不消除分支的方式 来merge dev)

  23. git stash - 将尚未完成需要保存的工作暂存到stash 中

  24. git stash list - 查看stash中有哪些内容

  25. git stash apply - 恢复stash内容到工作区,但是并不删除stash中的内容

  26. git stash drop - 删除stash中的内容

  27. git stash pop - 恢复stash内容到工作区,并删除stash中的内容

  28. git branch -D <name> - 强行删除某个分支,即使没有合并过

  29. 多人协作工作模式

  30. 试图用 git push origin branchname 推送本地更新

  31. 如果推送失败,则因为远程分支比本地分支新,要先 git pull 试图合并

  32. 如果合并有冲突,则解决冲突,并在本地提交

  33. 没有冲突或者冲突解决后,在用 git push origin branch-name 提交

  34. git remote -v 查看远程库信息

  35. git push origin branch-name 从本地推送分支

  36. git checkout -b branch-name origin/branch-name 从本地创建和远程对应的分支

  37. git branch --set-upstream branch-name origin/branch-name 建立本地分支和远程分支的关联

  38. git pull 从远程抓取分支

  39. git tag v0.9 6224937 (版本号) 针对某个版本号打上标签

  40. git tag - 查看标签

  41. git tag -a v0.1 -m "version 0.1 released" 3628164 - 给标签加上说明

  42. git show <tagname, v0.1 e.g.> - 查看标签说明

  43. git tag -s <tagname> -m "blablabla..."可以用PGP签名标签;

评论(0