git常用命令
https://juejin.im/post/6869519303864123399#comment
基本概念
版本库:使用 git init 时,会多一个 .git 文件夹,称之为版本库
工作区:本地项目存放文件的位置
暂存区:暂时存放文件的地方,add 命令将工作区的文件添加到缓冲区
本地仓库(Repository):commit 命令将暂存区的文件添加到本仓库
远程仓库(Remote):github托管,clone 命令将远程仓库代码拷贝下来,本地代码更新后,通过push到远程仓库
git文件状态
git status
changes not staged for commit 表示工作区有内容,但缓存区没有 需要 git add
changes to be commited 表示文件放在缓存区 需要 git commit
nothing to commit,working tree clean 直接将代码推送到远程即可
配置命令
- 列出当前配置
git config --list - 列出 Respository 配置
git config --local --list - 全局配置
git config --global --list - 系统配置
git config --system --list - 配置用户名
git config --global user.name "your name" - 配置用户邮箱
git config --global user.email"your email
分支
- 查看本地分支
git branch - 查看远程分支
git branch -r - 查看本地和远程分支
git branch -a - 从当前分支切换到其他分支
git checkout <branch name> - 创建并切换到新建分支
git checkout -b <branch name> - 删除分支
git branch -d <branch name> - 当前分支与指定分支合并
git merge <branch name> - 查看哪些分支已经合并到到当前分支
git branch --merged - 查看哪些分支没有合并到当前分支
git branch --no-merge - 查看各个分支最后一个提交对象的信息
git branch -v - 删除远程分支
git push origin -d <branch name> - 重命名分支
git branch -m <old name> <new name> - 拉取远程分支并创建本地分支
git checkout -b 本地分支名 orgin 远程分支名
git fetch origin <branch-name>:<local-branch-name>
fetch
- 将某个远程主机的更新,全部取回本地
git fetch <远程主机名> - 取回特定分支
git fetch <远程主机名> <分支名> - 取回特定分支到本地某个分支
git fetch origin:<local-branch-name>
撤销
- git chenkout – 撤销工作区修改
- git reset HEAD 暂存区文件撤销(不覆盖工作区)
- git reset --(soft | mixed | hard)<HEAD~(num)> | 版本回退 --hard 回退全部 包括HEAD、index、working tree;–mixed 回退部分,包括HEAD、index;–soft 只回退HEAD
状态查询
git status查看状态git reflog查看历史操作日志git log查看日志
文档查询
git help (--help)展示git 命令大纲git help -a展示git命令大纲全部列表git help展示具体命令说明手册
文件暂存
git stash save -a “message”添加改动到stashgit stash drop stash@{ID}删除暂存git stash list查看stash列表git stash clear删除全部缓存git stash pop stash@{ID}恢复改动
差异比较
git diff比较工作区与缓存区git diff --cached比较缓存区与本地库最近一次commit内容git diff HEAD比较工作区与本地最近一次commit内容git diff <commit ID><commit ID>比较两个commit之间差异
基本操作
- 创建本地仓库
git init - 链接本地仓库和远端仓库
git remote add origin - 检查配置信息
git config --list - 用户名和邮箱
git config --global user.name "yourname"git config --global user.email "your_email" - 查看远端仓库信息:
git remote -v - 远端仓库重新命名
git remote rename old new - 提交到缓存区
git add .全部上传到缓存区;git add指定文件 - 提交到本地仓库
git commit -m'sonme message' - 提交远程仓库
git push<远程主机名><本地分支名>:<远程分支名> - 查看分支
git branch - 切换分支
git checkout - 创建分支并切换
git checkout -b - 删除分支
git branch -d - 删除远程分支
git pushd -d
471

被折叠的 条评论
为什么被折叠?



