Rebase的使用以及修改远程库后rebese遇到的冲突问题

我平常进行git操作的顺序如下:

  1. 首先在vscode打开项目所在的文件夹

  2. 然后在VS Code的Terminal 中将该文件夹初始化为git仓库

    git init
  3. 然后添加远程库

    git remote add origin git@github.com:你的仓库名
  4. 建立完本地仓库与远程仓库连接,就可以开始推送。

  5. 我习惯使用rebase方式推送(merge与rebase的区别可见博主 ellenxx),推送流程为:

    git add .
    
    git commit -m "feat: The change of this version."
    
    git pull origin master --rebase
    
    git push origin master --force (首次推送建议 git push -u origin master --force)
    

    但是我这次发现README写的有错别字,所以在远端README直接编辑修改了readme.md文件,然后想使用git pull origin master --rebase将其同步到本地,出现了冲突:

    fatal: It seems that there is already a rebase-merge directory, and
    I wonder if you are in the middle of another rebase.  If that is the
    case, please try
            rm -fr ".git/rebase-merge"
    and run me again.  I am stopping in case you still have something

 中间又去掉--rebase       git pull origin master了一下  也出现一些错误,也记录一下:

git pull origin master

From gitee.com:funpony/learn-tex
 * branch            master     -> FETCH_HEAD
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.

然后参考git pull报错:Auto Merge Failed; Fix Conflicts and Then Commit the Result._谁不小心的的博客-CSDN博客

如果我们确定远程的分支正好是我们需要的,而本地的分支上的修改比较陈旧或者不正确,那么可以直接丢弃本地分支内容,运行如下命令(看需要决定是否需要运行git fetch取得远程分支):

git reset --hard origin master

fatal: ambiguous argument 'origin': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
HEAD is now at 2bc3331 update README.md.

然后重新使用git pull origin master --rebase之后提示如下:

From gitee.com:funpony/learn-tex
 * branch            master     -> FETCH_HEAD
fatal: It seems that there is already a rebase-merge directory, and
I wonder if you are in the middle of another rebase.  If that is the
case, please try
        git rebase (--continue | --abort | --skip)
If that is not the case, please
        rm -fr ".git/rebase-merge"
and run me again.  I am stopping in case you still have something
valuable there.

 然后根据提示git rebase --continue

git pull origin master --rebase

git rebase --continue

Successfully rebased and updated refs/heads/master.

便可继续git push origin master --force更新到本地,然后README就更新到本地了。

 git push origin master --force

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值