git常用操作

Git 常用操作

1 概念

概念 意义
HEAD 当前版本
HEAD^ 上一个版本
HEAD~N 往上第 N 个版本
origin 远程仓库的默认名称
master 默认主干分支名

2 指令

指令 意义
git init 创建仓库
git clone 克隆远程仓库
git status 当前状态
git diff 查看尚未暂存的文件更改
git diff —cached 查看已暂存的文件更改
git diff --staged 查看已暂存的文件更改
git checkout -- 撤销工作区 file 文件的修改
git reset HEAD 将暂存区文件 file 的修改撤销到工作区
git add 将文件修改添加到暂存区
git commit 提交修改(将暂存区提交到当前分支)
git push 将本地分支提交到远程分支(设置了upstream)
git push 将本地的 master 分支推送到远程 origin 分支
git pull 自动的抓取然后合并远程分支到当前分支
git fetch 从远程仓库中拉取所有本地还没有的数据
git reset --hard 版本回退,将HEAD指向 commit_id
git log --graph 查看分支合并图
git log -p - 最近n次提交的内容差异
git log --stat 查看每次提交的简略统计信息
git reflog 查看用户的每一次命令记录
git merge - -no-ff 合并 branch_name 分支到当前分支(不使用Fast Forward模式)
git branch 查看分支
git branch 创建分支 branch_name
git branch --merged 查看已经合并到当前分支的分支
git branch --no-merged 查看尚未合并到当前分支的分支
git branch -d 删除分支 branch_name
git checkout 切换到分支 branch_name
git remote 查看远程仓库信息
git remote -v 显示需要读写远程仓库使用的 Git 保存的简写与其对应的 URL
git remote show 查看远程仓库的更多信息
git remote add 添加一个新的远程 Git 仓库并指定一个简写
git remote rename 修改远程仓库 src 的简写名为 dst
git remote rm 移除远程仓库 remote
git checkout -b 克隆远程分支 remote_branch_name 到本地分支 local_branch_name
git branch --set-upstream 设置本地分支 local_branch_name 的upstream为远程分支 remote_branch_name
git tag 列出已有标签
git tag commit_id 上设置标签 tag_name ,如果省略 commit_id 则在最后的commit上打标签
git push --tags 将tag更新到远程仓库
git config --global 查看全局设置
git config --global core.autocrlf false 全局设置提交时自动将结束符 CRLF 转换成 LF

你可能感兴趣的:(编程日记,git)