git常用指令

设置用户信息:

git config [--global] user.email 

git comfig [--global] user.password

提交代码:

git commit -m [message]  //提交暂存区到仓库区

git commit [file1]  [file2]  -m[message] //提交暂存区的指定文件到仓库区

git commit -a //提交工作区自上次commit之后的变化,直接到仓库区

git commit --amend -m [message] //使用一次新的commit,替代上次提交。如果代码没有变化,则用来改写上次的提交信息

git commit --amend [file1] [file2]  //重做上一次commit,并包括指定文件的新变化

git push [remote] [tag] //提交指定tag

git push [remote] [branch] //上传本地指定分支到远程仓库

git push [remote] --force //强行推送当前分支到远程仓库,即使有冲突

git push [remote] --all //推送所有分支到远程仓库

git pull [remote] [branch]  //取回远程仓库的变化,并与本地分支合并

git stash  //暂时将未提交的变化移除

git stash pop //将未提交的变化移入

git stash list  //查看暂存文件

git stash apply [id] //取出指定的暂存文件

分支:

git branch //列出所有本地分支

git branch -r //列出所有远程分支

git branch -a //列出所有本地分支和远程分支

git branch [branch name] //新建分支

git branch -d [branch name] //删除分支

git checkout -b [branch] //新建一个分支,并切换到该分支

git checkout [branch-name] //切换分支

git checkout - //切换到上一个分支

git checkout [file]  //恢复暂存区的指定文件到工作区

git checkout [commit] [file] //恢复某个commit的指定文件到暂存区和工作区

git checkout //恢复暂存区的所有文件到工作区

撤销:

git reset [file] //重置暂存区的指定文件,与上一次commit保持一致,但工作区不变

git reset --hard //重置暂存区和工作区,于上一次commit保持一致

git reset --hard [commit] //重置当前分支的HEAD为指定commit,同时重置暂存区和工作区,与指定commit一致

git reset [commit] //重置当前分支的指针为指定commit,同时重置暂存区,但工作区不变

git reset --keep [commit] //重置当前HEAD为指定commit,但保持暂存区和工作区不变

 git reset --hard e377f60e28c8b84158  //回滚到指定版本

 git log --stat  //查看代码的版本号

合并:

git fetch [remote(远程名字,通常是自定义)] //下载远程仓库的所有变动 

git merge [branch] //合并指定分支到当前分支

git remote -v // 显示所有远程仓库

git remote add [shortname] [url] //增加一个新的远程仓库,并命名

git remote set-url myDMP http://10.38.34.223:10080/haohongmei/DMP_client.git  //更改地址

查看:

git status // 显示有更改的文件

不常用:

git archive //生成一个可供发布的压缩包

本地代码提交到远程仓库:

git init

git add .

git commit -m "提交描述"

git remote add origin ‘远程地址.git’

git pull --rebase origin master

git push -u origin master

 
原文地址:https://www.cnblogs.com/cxdxm/p/7776573.html