Git 常用的命令

154 阅读1分钟

查看所有分支

git branch -a

创建分支

git branch [name]

切换分支

git checkout [name]

查看分支的差别

git diff HEAD //查看本地与最新提交的工作树的差别

合并分支

git checkout master //切换到master分支

git merge --no--ff [name] // 加--no--ff 参数可以在历史记录中明确地记录本次分支的合并

git log --graph //以图表形式查看分支

回溯历史版本

git reflog //查看仓库的操作日志,找到要推历史的哈希值

 git checkout master

git reset --hrad [hash] //回溯到指定状态,只要提供目标时间点的哈希值

删除分支

git branch -d [name]

更新代码

git fetch [remote] //下载远程仓库的所有变动

git pull [remote] [branch] //取远程仓库的代码与本地分支合并