美文网首页git studyGit
【Git】记录一些Git常用命令

【Git】记录一些Git常用命令

作者: 浓眉毛de感冒药 | 来源:发表于2016-03-23 17:19 被阅读84次

    介绍

    分布式:

    三个区域:


    基础


    创建本地仓:git init

    克隆仓库:git clone 

          例子:git clone https://github.com/xxx/xxx.git

    获取远程分支代码:git fetch

          例子:git fetch origin master

    同步远程分支代码(fetch+merge):git pull

          例子:git pull origin master

    添加到本地缓存区:git add

          例子:git add xxx.java

    从本地缓存区删除:git reset HEAD

          例子:git reset HEAD xxx.java

    提交到本地仓:git commit

          例子:git commit -m "Fix bug xxx, by xxx"

    将本地仓的提交同步到远程仓:git push

          例子:git push origin master

    查看当前状态:git status

    查看提交记录:git log


    进阶


    查看本地分支:git branch

    查看远程分支:git branch -r

    查看所有分支:git branch -a

    切换分支:git checkout

          例子:git checkout branch_xxx

    创建本地分支:git branch xxx

          例子:git branch local_branch_xxx

    合并某分支到当前分支:git merge

          例子:git merge master

    将修改放入抽屉:git stash

    从抽屉中拿出改动:git stash pop

    查看抽屉记录:git stash list

    从抽屉中拿出某次记录:git stash pop xxx

          例子:git stash pop stash@{0}

    还原到某次提交的状态:git reset

          例子:git reset --hard xxxxxxxxxxxxxxxxxxxxxxxxxxx

    同步代码并且将本地提交推到最新(保证远程库提交顺序不变):git pull --rebase

          例子:git pull origin master --rebase


    其他

    打标签:git tag

          例子:git tag version_xxx

    查看reset缓存区(误操作恢复):git reflog

    本地分支替换远程分支(多用于远程分支回退某次提交):git push origin +branch_xxx:branch_xxx

          例子:git push origin +master:master

    查看帮助:git help

    查看配置:git config

    相关文章

      网友评论

        本文标题:【Git】记录一些Git常用命令

        本文链接:https://www.haomeiwen.com/subject/emollttx.html