• git中通过rebase操作解决冲突并提交PR


    我们通常通过 Github 进行协作工作,有时候在提交 PR 过程中,可能存在与别人已合并 PR 的冲突问题,此时便可以通过 rebase 操作解决这些问题并重新提交 PR,下面我们将这个过程简单描述记录一下。

    1.场景构造

    首先让我们在脑子中构造一个简单的场景:当我们提交一个 PR 到 Github 的主仓库时,此时通过 Github 的检查发现存在很多与主分支的冲突,这些冲突并不能通过在 PR 中进行对应文件的修改解决。

    2.rebase 过程

    此时我们需要做如下操作:

    • 在我们的 Github 分支上,拉取与主库的差距(Sync fork操作)
      在这里插入图片描述
    • 将我们自己分支的最新信息 pull 到本地的主分支(例如 dev 分支)
    • 切换到需要 rebase 的分支,执行命令对分支进行 rebase
      # chris @ ChrisdeMacBook-Pro in ~/dolphinscheduler/dolphinscheduler on git:PR-fix-wordcase-issue x [8:48:45] C:128
      $ git rebase dev
      
      • 1
      • 2
    • 此时通常会自动合并 master 分支中一些可合并的差异文件(Auto-merging),一些存在冲突的文件会列出来(CONFLICT),如下:
      $ git rebase dev
      Auto-merging dolphinscheduler-ui/src/views/projects/task/components/node/types.ts
      Auto-merging dolphinscheduler-ui/src/views/projects/task/components/node/format-data.ts
      Auto-merging dolphinscheduler-ui/src/views/projects/task/components/node/fields/index.ts
      Auto-merging dolphinscheduler-ui/src/locales/en_US/project.ts
      Auto-merging dolphinscheduler-task-plugin/dolphinscheduler-task-sql/src/main/java/org/apache/dolphinscheduler/plugin/task/sql/SqlTask.java
      Auto-merging dolphinscheduler-task-plugin/dolphinscheduler-task-procedure/src/main/java/org/apache/dolphinscheduler/plugin/task/procedure/ProcedureTask.java
      Auto-merging dolphinscheduler-task-plugin/dolphinscheduler-task-dataquality/src/test/java/org/apache/dolphinscheduler/plugin/task/dq/DataQualityTaskTest.java
      CONFLICT (content): Merge conflict in dolphinscheduler-task-plugin/dolphinscheduler-task-dataquality/src/test/java/org/apache/dolphinscheduler/plugin/task/dq/DataQualityTaskTest.java
      Auto-merging dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/test/java/org/apache/dolphinscheduler/plugin/task/api/parameters/SqlParametersTest.java
      Auto-merging dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parameters/SqlParameters.java
      Auto-merging dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java
      Auto-merging dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/DataSourceMapperTest.java
      Auto-merging dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/DatasourceUser.java
      CONFLICT (content): Merge conflict in dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/DatasourceUser.java
      Auto-merging dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DqRuleServiceTest.java
      Auto-merging dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java
      Auto-merging dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java
      Auto-merging dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DqRuleServiceImpl.java
      Auto-merging dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java
      Auto-merging docs/configs/docsdev.js
      error: could not apply 1df0c5016... modify Datasource to DataSource on all related files
      Resolve all conflicts manually, mark them as resolved with
      "git add/rm ", then run "git rebase --continue".
      You can instead skip this commit: run "git rebase --skip".
      To abort and get back to the state before "git rebase", run "git rebase --abort".
      Could not apply 1df0c5016... modify Datasource to DataSource on all related files rebase and repush
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13
      • 14
      • 15
      • 16
      • 17
      • 18
      • 19
      • 20
      • 21
      • 22
      • 23
      • 24
      • 25
      • 26
      • 27
    • 接下来我们需要使用编辑工具(例如 vim)修改这些 CONFLICT 涉及的文件,把其中 “HEAD” 后的冲突按照你的想法进行修改,然后保存
    • CONFLICT 文件都解决后,执行 git add xxx,然后继续执行 git rebase --continue
    • rebase 完成后,可以执行 git push origin pr-name -f,强制更新到远程仓库的对应pr上
    • 注意:如果在 rebase 过程中,您不想继续了,也可以执行 git rebase --abort 来终止 rebase

    整个 rebase 的过程记录大体如上,基本可以解决所有 PR 提交过程中产生冲突的情况,希望能帮助大家。

  • 相关阅读:
    Dynamsoft Label Recognizer SDK FOR .CPP.NET
    策略路由典型配置:通过流策略实现策略路由(即重定向到不同的下一跳)
    C/C++ P2P自定义发现协议 Xndp。
    Python多方法高效匹配、关联操作两个列表
    postgresql-通用表达式
    PX4模块设计之二十二:FlightModeManager模块
    mq 消息队列
    【Redis】深入探索 Redis 主从结构的创建、配置及其底层原理
    【.NET 深呼吸】全代码编写WPF程序
    vue面试题4
  • 原文地址:https://blog.csdn.net/chrisy521/article/details/126883159