GIT基本命令介绍

1.git remote

  •    git remote -v| --verbose 查看仓库详细信息
  •    git remote add <name> <url> 关联远程库.如果你本地新建项目,需要关联远程的库就用这个命令
  •    git remote prune <name>  删除无用的远程库
  •    git remote show <reponame> 查看远程仓库信息

2.git branch

  •   git branch 查看本地分支
  •   git branch <branchname> 新建分支
  •   git branch -a|--all 查看远程+本地分支
  •   git branch -r|--remotes 查看远程分支
  •   git branch -b <branchname> 本地从现有分支新建分支并切换
  •   git branch <newbranch> <sourcebranch> 新建分支
  •   git branch -m <oldname> <newname> 分支重命名
  •   git branch -d|--delete 删除本地分支
  •   --merged 查看哪些分支已经被并入当前分支
  •   --no-merged 查看尚未合并的分支

  

3.项目初始化

git config --global user.name <name>  # 配置用户名
git config --global user.email <email> # 配置邮箱
git init #本地添加.git目录,track项目

 

4.生成密钥

ssh-keygen -t rsa -C  'usertest@usertest'  

 

5.  push

  • 本地分支推送到远程
git push origin localbranch
  • 删除远程分支
$ git push origin :serverfix
To git@github.com:schacon/simplegit.git
 - [deleted]         serverfix
  •  本地分支推送到远程
$git push origin <localbranch>:<remotebranch>

 6. diff

  • 比较两个分支的差异
$git diff branch1 branch2 --stat
  • 比较两个分支某文件的差异
$git diff branch1 branch2 -- YOURFILE

7. log

  • 查看某位作者的日志
$git log --author=作者名
  • 查看简洁日志
$git log --oneline .
  • 查看详细日志
$git log -p .
  • 查看当前分支是基于哪个分支创建的
$git reflog --date=local --all | grep <from_branch>

 

8. add

  • 将当前目录添加到暂存区
$git add .
  • 将当前文件添加到暂存区
$git add [file1] [file2]

9. commit 将暂存区内容添加到本地仓库中

  • 将当前目录添加到本地仓库中
$git add .
  • 将当前文件添加到本地仓库中
$git add [file1] [file2] ...[fileN]

10. checkout 

  • 切换分支
$git checkout <branch>
  • 撤销暂存区的修改
$git checkout .
  • 切换回上次操作的分支
$git checkout -

11. reset

  • 撤销最近一次的commit
$git reset HEAD  <file1>...

12. chery-pick 

  • 选择某一次commit进行合并
$git chery-pick <commitID>

13. stash

  • 暂存当前修改,跟add并不同。通常是你当前修改还没有完成,需要紧急存起来去处理一个BUG或添加一个新的功能时,并不想提交当前的修改。
$git stash save "save message"
  • 取出最近一次的暂存内容
$git stash pop
  • 查看暂存列表
$git stash list

14. status

  • 查看当前项目的状态
$git status

15. rebase

  • 合并
$git rebase <frombranch>

16. show

17. tag

18. switch

19. rm 

20.blame

  • 查看某文件修改记录
$git blame <filename>

 

 

   

posted @ 2019-02-12 16:44  琵琶真的行  阅读(217)  评论(0编辑  收藏  举报