• 远程分支替换本地分支


    方法一:

    git pull” 强制覆盖本地文件 放弃本地修改,使用服务器代码覆盖本地的Git命令如下:

    git fetch --all
    
    git reset --hard origin/master 
    
    git pull

    上面代码使用master分支覆盖本地代码。如果需要使用其它分支覆盖本地代码,则更改第二条命令的参数。

    方法二:

    git 拉取命令(pull)的标准格式是:

    git pull <远程主机名> <远程分支名>:<本地分支名>git pull <远程主机名> <远程分支名>:<本地分支名>

    一般我们简写成

    git pull

    代表从远程分支拉取到当前的本地分支。

    有的时候,已经知道远程分支与本地分支有不同的commit,比如本地分支有一个临时的commit,远程分支并没有。是不能简单执行git pull的,会报错。

    此时如果只是想放弃本地的临时提交,强制将远程仓库的代码覆盖到本地分支。

    就要用到--force参数,强制拉取功能 git manual中关于--force参数的说明

     --force
    When git fetch is used with <src>:<dst> refspec it may refuse to update the local branch as discussed in the <refspec> part of the git-fetch(1) documentation. This option overrides that check.

    命令格式如下:

    git pull --force  <远程主机名> <远程分支名>:<本地分支名>

    示例:

    git pull --force origin master:master
    From https://gitee.com/l0km/myprj
     + e072b6b...d5a5684 master     -> master  (forced update)/** 强制更新 */
    warning: fetch updated the current branch head.
    fast-forwarding your working tree from
    commit e072b6bf59ab4d371b24966005b6d2b40e30bbw5.
    Already up-to-date.

    方法三: 

    删除您的本地分行: git branch -d master 

    获取最新的远程分支:  git fetch origin master 

    重建基于远程的本地分支: git checkout -b master origin/master 

    参考链接:

    1. 远程分支替换本地分支
    2. https://www.1024sou.com/article/529973.html

     

  • 相关阅读:
    P1169 [ZJOI2007]棋盘制作[悬线法/二维dp]
    P2279 [HNOI2003]消防局的设立[树形dp]
    Django项目部署
    Python3编译安装以及创建虚拟运行环境
    ASA与N6K对接
    Django使用admin管理后台管理数据库表
    WebStrom配置
    H3C常用配置和命令
    VPC配置介绍
    Linux下编译安装MySQL
  • 原文地址:https://www.cnblogs.com/2018shawn/p/15983590.html
Copyright © 2020-2023  润新知