git常用操作

git init 初始化

git add . 将所有文件添加到暂存区

git commit -m “msg” 提交更改并添加提交信息

git commit -a -m “msg” 不用添加到暂存区,直接提交并添加提交信息

git commit --amend “msg” 增补提交,会使用与当前提交节点相同的父节点进行一次新的提交,旧的提交将会被取消。

git commit -m “msg”  --no-verify 忽略代码检查提交

git remote add origin [git address] 添加远程仓库仓库地址

git push -u origin master 将本地的master分支推送到origin主机,同时指定origin为默认主机,之后可以用git push代替git push origin master

git remote set-url origin  [git address] 更改远程仓库地址

git push origin -d BranchName 删除远程git服务器上的分支

git remote prune 清理无效的远程追踪分支

git branch [分支] 创建本地分支 

git checkout -b [local-branch-name] origin/[branch-name] 在本地新建分支并切换到该分支

git checkout [分支] 切换本地分支

git clone [git address] local-name 把远程仓库代码clone到本地,可以自定义一个本地的名字

git config  [--local, --global, --system] user.name 'your name'

git stash save 'message' 存储当前修改

git stash list 查看存储列表

git stash apply stash@{0} 恢复stash内容

git stash drop stash@{0} 删除已经恢复的stash记录

查看信息

git remote -v 查看远程仓库信息

git config [--local, --global, --system]  [--list, -l] 查看git配置信息

git branch -a 查看分支(包括远程分支)

git branch -r 查看远程分支

git log 查看log(q 退出log)

git reflog 查看提交日志

git status 查看文件状态,用于判断是否还有未暂存的文件,是否还有未提交文件

 其他操作

git pull --rebase 把默认的拉取+融合,改为拉取+变基 等同git fetch + git rebase

git rebase 中reword 可以改变提交注释

git reset --hard HEAD@{3} 重置到某个提交

git cherry-pick ccommitID 将其他分支的某次提交合并到本分支上

git fetch upstream 获取远程代码

git merge upstream/master 合并远程代码

git merge --no-ff:不使用fast-forward方式合并,保留分支的commit历史

git merge --squash:使用squash方式合并,把多次分支commit历史压缩为一次

当编辑提交信息后输入:wq保存并退出编辑

原文地址:https://www.cnblogs.com/nightstarsky/p/9596808.html