git 常用命令

  1. git init . #当前目录初始化为 git 代码仓库
  2. git init youdir #创建目录,并初始为 git 代码仓库
  3. git clone url #克隆远程代码仓库
  4. git config --list # 显示配置信息
  5. git config --system user.email "test@gitcmd.com" # git 配置系统级别的配置文件
  6. git config --global user.name "test" # git 配置用户级别的配置文件
  7. git config --local user.name "test" # git 配置当前项目的配置文件
  8. git add . # git 把当前的全部文件添加到暂存区
  9. git add filename # git 添加特定的文件到暂存区
  10. git status # 显示当前的状态
  11. git log # 显示当前分支的历史信息
  12. git log -S “keyword" # 在历史信息中搜索
  13. git rm filename # 删除工作区的文件,并将删除操作放入暂存区
  14. git rm --cached filename # 停止追踪该文件,该文件不会再工作区删除,提交后生效。
  15. git mv filea fileanew # 修改名字,并放入暂存区
  16. git commit -m "submit msg" # 提交暂存区的内容到 git 仓库
  17. git commit filea fileb -m "msg" # 提交指定的文件,可以是1个或者多个
  18. git commit -v # 提交显示diff信息
  19. git commit --amend -m "msg" # 替代上次的提交,可以修改上一次的提交信息
  20. git commit --amend filea fileb # 从新提交,并包括指定文件的变化
  21. git branch # 列出分支
  22. git branch -r # 列出远程分支
  23. git branch -a # 列出本地分支
  24. git branch "new_branch" # 新建一个分支,但不切换的的新的分支
  25. git branch -b “new_branch" # 新建并且切换的新的分支
  26. git checkout "new_branch" # 切换到指定的分支
  27. git checkout - # 切换到上一个分支
  28. git merge "branchx" # 合并指定分支到当前的分支
  29. git branch -d "branchname" # 删除指定分支
  30. git breach origin --delete "branchname" # 删除远程分支
  31. git tag # 列出tag
  32. git tag "tagname" # 新建一个 tag
  33. git tag -d ”tagname" # 删除一个tag
  34. git show tag # 查看 tag 信息
  35. git diff # 显示暂存区和工作区的差异
  36. git diff --cached file # 显示暂存区和上一个commit 的禅意
  37. git diff HEAD # 显示工作区和当前最近分支的差异
  38. git fetch [url] # 下载远程仓库的所有变化
  39. git remove -v # 显示远程所有的仓库
  40. git remove add "shortname" "url" # 增加一个远程仓库
  41. git pull "url" # 取回远程仓库的变化
  42. git push "url" -all # 本地的变化推送的所有的远程仓库
  43. git checkout file # 恢复暂存区的文件到工作区
  44. git chekckout "commit" "file" # 恢复历史提交的文件到工作区
  45. git reset --hard # 重置暂存区的文件