• Git标签使用技巧


    从远端拉取指定分支

    一定遇到这种情况,github看到一个心仪的开源仓库,但是分支太多,我们只想要我们需要的分支。

    git clone -b <指定分支名> <远程仓库地址>
    

    切换到指定分支

    分支众多,要切换到指定分支

    #branch分支管理
    git branch
    git switch 分支名
    

    创建标签

    git tag v1.0
    #默认标签是打在最新提交的commit上
    

    为指定Commit Id创建标签

    上面标签,是为最新的一次提交创建的。但是我们想吃后悔药——为之前的提交创建标签,该怎么做呢!?

    $ git log --pretty=oneline --abbrev-commit
    $ git tag 标签值 commitId
    
    #查看标签信息
    $ git show 标签值
    

    删除标签

    $ git tag -d v0.1
    
    #删除远程标签
    $ git tag -d v0.9
    $ git push origin :refs/tags/v0.9
    

    推送标签至远程仓库

    #推送指定标签至远程
    $ git push origin v0.1
    
    #推送全部标签至远程
    $ git push origin --tags
    

    切换至某个标签

    #tag标签管理
    git tag
    #切换
    git checkout tag值
    

    本地关联远程

    一般情况,常规操作是先在github或者gitee创建远程仓库,然后

    git clone 
    git add -A
    git commit -m ""
    git push -u origin master
    

    但是还有一种情况,先通过git init创建的本地仓库,突然发现今天写的代码太优美了,要整个远程仓库存起来。

    #初始化-建立本地仓库
    git init
    
    #把本地仓库与远程仓库关联
    git remote add origin git@gitee.com:RandyField/xxxxx.git
    
    #push
    git push -u origin master
    
    #但是可能会出现如下错误
     ! [rejected]        master -> master (non-fast-forward)
    error: failed to push some refs to 'git@gitee.com:RandyField/xxxxx.git'
    hint: Updates were rejected because the tip of your current branch is behind
    hint: its remote counterpart. Integrate the remote changes (e.g.
    hint: 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    
    #原因是创建远程仓库,和本地仓库没有关联,也具有差异
    
    #把远程仓库和本地同步,消除差异,把两段不相干的分支进行强行合并
    git pull origin master --allow-unrelated-histories 
    
    git add -A
    git commit -m "[dev]init"
    git push -u origin master
    
  • 相关阅读:
    友链
    OI日常
    P4451 [国家集训队]整数的lqp拆分 生成函数
    AT4831 [ABC155F] Perils in Parallel 生成树
    P4438 [HNOI/AHOI2018]道路 树DP
    CF383E Vowels 子集DP 容斥
    P5488 差分与前缀和 生成函数+多项式EXP
    CF115E Linear Kingdom Races 线段树优化DP
    CF49E Common ancestor 区间DP
    P5047 [Ynoi2019 模拟赛] Yuno loves sqrt technology II 莫队二次离线
  • 原文地址:https://www.cnblogs.com/chonglu/p/15622036.html
Copyright © 2020-2023  润新知