Git合并冲突:找不到问题
一些背景故事!
我一直在使用 git 为一个开源包做出贡献,我在这方面有点新手。我知道一些基本的东西。此外,我还读到如果发生合并冲突,我们可以遍历文件,标记可以帮助我们找到同一文件的两个版本中相互冲突的代码块。
最近第一次遇到合并冲突,是在 Jupyter notebook 文件(.ipynb)上。但是,合并冲突的标记使 Jupyter 无法读取笔记本。所以,我尝试了 JSON 编辑器和 VS CODE 和 Notepad++。虽然我现在可以看到该文件,但它真的很乱,因为它不仅包含 Jupyter notebook 的所有元数据,而且甚至在执行次数方面也显示冲突。另外,如果笔记本中有一个图形作为一个单元格的输出,它会被转换成很多字符,向下滚动并浏览它们是很头疼的。
在搜索 google 和 stackoverflow 并与项目所有者讨论问题后,我们决定采取另一种方法。但是,它不起作用。(我在下面进行了解释,但首先我需要提供更多信息。请耐心等待)
根据提交的历史记录,我应该是在本地通过更改 PARENT 分支上的相同文件而在本地创建此类冲突的人,因为没有人在上游更改它(在原始存储库中)
因此,请让我首先简要介绍一下分支和我对文件所做的一些更改。
- 在分叉和克隆之后,我创建了一个分支
branch-A - 我更改了笔记本“notebook-file”
- 我做了拉取请求(PR)
- 我创建了 A 的一个子分支,我们称之为
sub-branch-of-A - 切换到子分支后,我更改了两个 .py 文件,然后也更改了
notebook-file - 合并
sub-branch-of-A成branch-A
在 my 中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
:
我附上了同样的东西,但以图像格式附加,因为我需要突出显示两个提交:
图像底部突出显示的提交是我可以在分叉中看到的提交。另一个突出显示的提交是当我认为我可以通过这样做来解决它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.fileand相同的情况下,git diff ...MERGE_HEAD that.file只有当 Git 解决由以前的交叉合并引入的异常差异时,即具有不同内容的多个等效合并基础,而不是您在大多数历史中看到的东西,基础内容不是来自单个现有的基础提交。
- 接受答案,我相信赏金会在延迟后自动授予。如果您可以教过滤器从笔记本中去除无用的元数据内容,您可以区分过滤结果,请查看 textconv。* 非常* 方便从机器生成的文本装饰中去除噪音,当你在这里做的时候寻找相应的变化。