Git合并冲突:找不到问题

如何解决Git合并冲突:找不到问题

一些背景故事!
我一直在使用 git 为一个开源包做出贡献,我在这方面有点新手。我知道一些基本的东西。此外,我还看到如果发生合并冲突,我们可以遍历文件,标记可以帮助我们找到同一文件的两个版本中相互冲突的代码块。

最近,我第一次遇到了合并冲突,它是在 Jupyter notebook 文件 (.ipynb) 上。但是,合并冲突的标记使 Jupyter 无法读取笔记本。所以,我尝试了 JSON 编辑器和 VS CODE 和 Notepad++。虽然我现在可以看到该文件,但它真的很乱,因为它不仅包含 Jupyter notebook 的所有元数据,而且甚至在执行次数方面也显示冲突。另外,如果笔记本中有一个图形作为一个单元格的输出,那么它被转换成很多字符,向下滚动浏览它们很头疼。

在google和stackoverflow上搜索并与项目所有者讨论这个问题后,我们决定采取另一种方法。但是,它不起作用。 (我在下面解释过,但首先我需要提供更多信息。请耐心等待)

根据提交的历史记录,我应该是在本地通过更改父分支上的相同文件而在本地创建此类冲突的人,因为没有人在上游(在原始存储库中)更改它

因此,请让我首先简要介绍一下分支和我对文件所做的一些更改。

  • 分叉和克隆后,我创建了一个分支 branch-A
  • 我更改了笔记本“notebook-file”
  • 我做了拉取请求 (PR)
  • 我创建了 A 的一个子分支,我们称之为 sub-branch-of-A
  • 切换到子分支后,我更改了两个 .py 文件,然后也更改了 notebook-file
  • sub-branch-of-A 合并到 branch-A

在我的 branch-A 中,我做了:git push origin branch-A 但我收到了 non-fast-forward 错误。这意味着发生了分歧。对?所以,我做了 git pull origin branch-A 来解决它,但我遇到了 notebook-file 的合并冲突。

替代解决方案

所以,我被告知我可以将文件复制到本地 git 存储库之外的某个地方,然后执行 git checkout notebook-file 以在发生分歧的父节点中获取文件。对?然后,如果我执行 git pull ... 应该没有问题(然后我可以包含该复制文件的更改)

但是...

我再次遇到合并冲突错误。我疯了,尝试了几件事,但仍然没有。

我附上了下面的 git 日志。 我说的分支是Snippets_Tutorial,它的子分支是Snippets_Regime。如果我没记错的话,我用 git checkout -b Snippets_Regime Snippets_Tutorial 创建了那个子分支。正如我之前提到的,我切换到子分支 Snippets_Regime 并对 somefile.py 文件和 notebook-file 进行了一些更改。然后,我将其合并到 Snippets_Tutorial 中。

$ git log --all --graph --decorate --oneline
* 8d62ec9 (MERLIN_Tutorial) modify the code for comparing MERLIN3 (MATLAB) and MERLIN (Python) implementation
* 4952e92 (origin/MERLIN_Tutorial) Use MERLIN (of Table3) on Mars Science Labratory data to reproduce Fig. 17 of paper (top and botthm)
* 8d04aaa plot discords of NYC TAXI data that discovered by ONLY python or ONLT matlab
* 2bbb569 Revise DRAG,Implement MERLIN,and Try MERLIN on data
* 361824f correct the implementation of the algorithm to return correct NN index of the discords
* dd6eb87 Revise the implementation of DRAG algorithm provided in Table 1 and 2.
*   1adb0f6 Allow merge from main to my local branch
|\
* | 62e6b29 Add Tutorial for Matrix Profile XXI: MERLIN algorithm #Issue 417
| | * 81798ab (HEAD -> Snippets_Tutorial) copy back Snippet Tutorial notebook
| | * e680e0f allow git to track the file (?)
| | * eef7018 Copy back Snippet Tutorial notebook to the Snipperts_Tutorial branch
| | * 15ebf32 remove snippet tutorial local file from its developing branch tto allow merge from the main
| | *   06c05e3 merge updated files from origin to my branch (?)
| | |\
| | |/
| |/|
| * | 4c05d54 (upstream/main,origin/main,origin/HEAD,main) Fixed #414 Added fork syncing,checkbox fix to Contribute.ipynb
|/ /
| * be9169c resolve issues raised by flake8
| * c7a2654 (Snippets_Regime) update the notebook according to the updated version of snippet module
| * e4c0696 Change snippet_regime from list to numpy array
| * c6ab996 correct the block of code for plotting the snippets regimes
| * ed1b1a6 add the plot of snippets regime to check out the functionality of snippets_regime added to snippets modules
| * 52da7b2 remove blank line after docstring of a function
| * 6d599df use stumpy.mplstyle to refactor the rcparams
| * e968427 add the slices of indices for each snippet in the output
| * 910746e [WIP]: save temp changes
| * 911abaf [WIP] Revise the intro section and legend of figures
| * b47e727 Add textual context and Improve the flow and figures
| * b9ad95e Add the introduction part
|/
* 589630e Saved widget state in notebook
* 21abb19 Added empty array _get_array_ranges unit test
* 9f6c2cf Fixed #413 Edge Case in core._get_array_ranges
* db1c694 Updated STUMPY_EXCL_ZONE_DENOM test
* 7383cb7 Added gpu_stimp
* 1f1f426 Added stimped feature
* e87f9ad Fixed #411 Bad import of config settings
* 50a9089 Replaced mpl params with style file
* f80e6ce Fixed typo
* 000a0e6 Replaced nan_to_num in unit test
* c67fd56 Fixed #409 Added IPython to docs/requirements.txt; #409 (#410)
* 248ce34 Fixed typo in docstrings of subspace & _subspace (#406)
* c178889 Replaced nan_to_num with np.isnan
* 05cfc52 Fixed #237 Added STIMP (aka SKIMP) feature
* a59d57f Added bonus section on interpreting mp columns
* 9bf1944 Updated conda installation and environment
* 856dc75 Moved additional excl_zone parameter to config.py
* 48864d2 Added motif_idx with include/discords subspace example
* ebb3559 Added include/discords tutorial example to subspace
* 03bbdca Fixed grammar in contributor guide
* 3832b21 Fixed #385Clarifying the "Make your Changes" Section of Contributor Guide (#386)
| * 5f004a2 (origin/Snippets_Tutorial) [WIP] Revise the intro section and legend of figures
| * 0afad01 Add textual context and Improve the flow and figures
| * 9d0095a Add the introduction part
|/
| * 7a36675 (origin/Geometric_Chain,Geometric_Chain) Add chain analysis for respiration data and reproduce Table 2 of the paper
| * 01dc5d3 Correct/Update the markdowns and the result (adding discussion and figures)
| * e27b6b9 Correst docstrings of several functions
:

我附上同样的东西,但采用图像格式,因为我需要突出显示两个提交:

enter image description here

图像底部突出显示的提交是我在 fork 中看到的提交。 另一个突出显示的提交是我认为我可以通过在 git merge main <branch> 处执行 <branch> 来解决它。蓝色曲线包围的部分是合并的地方,不知道这里发生了什么(我的意思是,我无法完全记住我发疯时使用的确切 git 命令)

如果我遗漏了什么,有人可以帮助我/指导我吗?

解决方法

在合并冲突解决中重要的是两个技巧和基础,以及冲突。其他一切都是噪音。

git diff :1:that.file :2:that.file
git diff :1:that.file :3:that.file 

将向您展示 git 合并的两组更改。在几乎所有与 git diff MERGE_HEAD... that.filegit diff ...MERGE_HEAD that.file 相同的情况下,只有当 Git 解决由以前的交叉合并引入的异常差异时,即具有不同内容的多个等效合并基础,这在大多数历史中都不是你看到的,基础内容不是来自单个现有的基础提交。

,

在分布式版本控制系统中合并冲突是不可避免的,因为分支总是发散的。您想要的不是避免合并冲突,而是一种解决它们的有效方法。

问题——正如您亲身经历的那样——是 Jupyter Notebooks 的文件格式不是很容易手动编辑,因此 git 提供的所有默认工具来解决合并冲突对您没有多大帮助。

您需要的是 mergetool

有许多不同的合并工具以更加用户友好的方式呈现合并冲突,但它们无法解决您在 Jupyter Notebooks 格式方面的主要问题。

这就是 nbdime 来的地方。 nbdime 为您配置了 git,因此当发生冲突时,您可以使用其合并工具直观地解决冲突,而无需查看文本文件,因此可以避开所有 JSON 文件的噪音。

用Python的pip安装nbdime,然后配置git使用即可:

nbdime config-git --enable --global

您应该可以通过其合并工具来解释合并冲突。

nbdime mergetool

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res