zoukankan      html  css  js  c++  java
  • git命令


    1、修改文件后提交
    git add file.txt
    git commit -m "提交日志"

    2、提交后恢复到某历史版本
    (1)git log [--pretty=oneline]
    查看commit日志,得到commitID
    (2)git reset --hard commitID

    3、从版本库恢复之前版本(旧于当前版本)
    (1)恢复到当前版本的上一个版本
    git reset --hard HEAD^
    (2)恢复到当前版本的上两个版本
    git reset --hard HEAD^^

    git reste --hard HEAD^2

    4、从版本库恢复到之后的版本(新于当前版本)
    (1)git reflog
    可以看到当前之前和之后的commitID
    (2)使用commitID 恢复
    git reset --hard commitID


    5、放弃工作区的修改
    命令: git checkout -- filename
    (1)该文件修改后没有放入暂存区(没有git add)
    执行命令后工作区的文件会被版本库的HEAD版本替换
    (2)该文件修改后放入(过)暂存区(有git add)
    执行命令后工作区的文件会被暂存区(stage)的版本替换


    6、已经放到暂存区的文件,如何撤销?
    即 已经git add filename,如何撤销?
    (1)将版本库中的最新版本回退到暂存区
    git reset HEAD filename
    (2)把暂存区的回退到工作区
    git checkout -- filename


    7、查看分支
    git branch
    git branch -a

    8、创建分支
    git branch dev

    9、切换分支
    git checkout dev
    or
    git switch dev

    10、创建并切换到新分支
    git checkout -b dev
    or
    git swtich -c dev

    11、合并某分支到当前分支
    git merge dev

    12、删除分支
    git branch -d dev

    13、用图形形式查看日志
    git log --graph [--pretty=oneline] [--abbrev-commit]

    14、禁用Fast forward 模式进行分支合并
    禁用FF时,git会在merge时生成一个新的commit
    git merge --no-ff -m "this is a xx commit" dev

    15、在分支dev开发的过程中需要紧急修复一个bug怎么办?
    (1)在dev分支上
    git stash (前提是保证此时所有的文件都曾经git add 过)
    (2)切换至master分支
    git checkout master
    (3)新建并切换到bug分支
    git checkout -b issure1
    (4)修复问题后 git add & git commit
    (5)切换至master
    git checkout master
    (6)将bug修复分支合并至master
    git merge --no-ff "merge from issure1" issure1
    (7)处理可能的冲突后提交
    git add & git commit
    注意:后面需要这里的 commitID
    (8)回到dev分支
    git checkout dev
    (9)将master上修复的bug同步到dev
    git cherry-pick commitID
    (10)恢复之前的dev现场
    git stash pop
    (11)处理可能的冲突
    git add & git commit

    16、强制删除一个分支
    当尝试删除一个还没有被合并过的分支时会提示删除失败
    此时就需要强制删除
    git branch -D dev

    17、查看远程库信息
    git remote -v

    18、从本地推送分支
    git push origin branch-name
    如果推送失败则先 git pull


    19、从本地创建和远程分支对应的分支
    git checkout -b branch-name origin/branch-name

    20、建立本地分支和远程分支的关联
    git branch --set-upstream branch-name origin/branch-name

     

    21、git rebase
    应用场景:基于master拉取分支dev,在dev上开发了一段时间后,此时master上已经被其他小伙伴推送了一些,此时可以merge也可以rebase;
    在dev分支上,git rebase master
    此时dev分支的起点即为mster最新的,相对于merge,rebase操作会丢失历史信息。


    22、创建标签
    标签指向commit
    git tag <tagname> [commitID]
    git tag -a <tagname> -m "some notes" [commitID]

    查看tag
    git tag
    or
    git show <tagname>

    23、推送标签到远程库
    (1)单个标签
    git push origin <tagname>
    (2)所有标签
    git push origin --tags


    24、删除标签
    (1)删除本地标签
    git tag -d <tagname>
    (2)删除远程标签
    先从本地删除,然后再推送删除到远程
    git push origin :refs/tags/<tagname>

     

     

     

     

    **********************技术交流请 email:cuihao0532#163.com 欢迎转载,转载请注明出处!***************************** 如果对本文满意请扫描文章左侧【二维码添加微信】获取更多好玩、有趣、有益、有营养的料, 你我共同成长!Y(^_^)Y
  • 相关阅读:
    MyBatis 最常见错误,启动时控制台无限输出日志
    mybatis.generator.configurationFile
    MBG 相关资源链接
    MyBatis Generator 详解 专题
    随笔分类
    android 播放assets文件里视频文件的问题
    AssetManager中的路径参数不能包含"assets/"
    Android---intent传递putStringArrayListExtra
    android中使用setVideoURI()播放视频
    vitamio官方demo源码分析
  • 原文地址:https://www.cnblogs.com/cuish/p/15087200.html
Copyright © 2011-2022 走看看