git常用命令

149 阅读1分钟

git安装流程链接

blog.csdn.net/weixin_4763…

查看git版本:

$ git version

远程仓库的使用:

git init ‘初始化(创建)本地仓库’

git config user.name    ‘查看当前git用户名’   
git config --global user.name "xxx(新的用户名)" ‘修改用户名’

git config user.password    ‘查看当前git密码’
git config --global user.password "xxxx(新的密码)"  ‘修改git密码’

git config user.email    ‘查看git邮箱地址’
git config --global user.email "xxxx@xxx.com(新的邮箱)"  ‘修改git邮箱’

git clone "远程仓库URL" ‘拉取远程仓库的代码’         

git remote -v     ‘查看当前的远程仓库’

$ git remote add "name" "远程仓库的url" ‘创建远程仓库’

$ git push -u "name" "branch name"‘代码推送到远程仓库’

$ git pull -u "name" "branch name" ‘拉取指定分支的远程代码’

分支的创建切换:

$ git branch      ‘查看所有分支’    

$ git branch "branch_name"    ‘创建分支’

$ git checkout -b "本地分支名" "origin/远程分支名"    ‘拉取远程仓库指定分支代码并建立本地分支’

$ git checkout "branch_name"  ‘切换分支’

$ git branch -d "branch_name"   ‘删除分支’  

$ git branch -vv   ‘查看映射关系’  

$ git branch -u "origin/分支名"  ‘建立映射关系’

$ git merge "branch_name" ‘合并到当前你选择的分支中’  

代码提交:

$ git add.   ‘提交到暂存区’  

$ git commit -m '提交名称'   ‘提交到仓储区’  

$ git push    ‘提交到远程仓库’   

$ git status    ‘查看代码提交状态’

$ git reset --soft <版本号>  ‘push的版本回退’

临时存储代码:

$ git stash save "暂存的备注"   ‘临时储存修改’    

$ git stash pop    ‘取回暂存的代码’ 

$ git stash list    ‘查看暂存记录’     

$ git stash clear    ‘清空暂存’

提交记录:

$ git log    ‘显示所有的提交记录’   

$ git shortlog   ‘显示命令摘要’

$ git show "your_commit_hash"   ‘显示特定的提交信息’

$ git reset --hard "目标版本号"   ‘回退指定版本’  

$ git push -f   ‘强制推送’