git:pull --force 强制覆盖本地的分支

版权声明:本文为博主原创文章,转载请注明源地址。 https://blog.csdn.net/10km/article/details/84669270

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

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

一般我们简写成

$ git pull

代表从远程分支拉取到当前的本地分支。
有的时候,已经知道远程分支与本地分支有不同的commit,比如本地分支有一个临时的commit,远程分支并没有。是不能简单执行git pull的,会报错。
此时如果只是想放弃本地的临时提交,强制将远程仓库的代码覆盖到本地分支。就要用到--force参数,强制拉取功能
git manual中关于--force参数的说明
在这里插入图片描述
命令格式如下:

$ 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.

猜你喜欢

转载自blog.csdn.net/10km/article/details/84669270