一些背景故事!
我一直在使用git为开源软件做贡献,但在这个领域我有些新手。我知道一些基础知识。此外,我还了解到,如果发生合并冲突,我们可以检查文件标记,找到两个版本的同一文件中存在冲突的代码块。
最近,我第一次遇到了合并冲突,而且它是在Jupyter笔记本文件(.ipynb)上。然而,合并冲突的标记使得Jupyter无法读取笔记本。因此,我尝试了JSON编辑器、VS CODE和Notepad++。虽然现在我能够看到文件,但非常凌乱,因为它不仅包含了所有Jupyter笔记本的元数据,而且即使在执行次数方面也会显示冲突。另外,如果一个单元格的输出是图形,它会被转换成很多字符,而向下滚动浏览是头痛的。
在搜索谷歌和stackoverflow以及与项目所有者讨论后,我们决定采取另一种方法。但是,它没有成功。(我之后会解释,但首先我需要提供更多信息。请耐心等待)
根据提交历史,我应该是在本地创建了这样的冲突,可能是因为在父分支上更改了相同的文件,因为没有人在上游(in the original repo)更改它
因此,请允许我首先简要介绍一下分支以及我对文件所做的一些更改。
- 分叉并克隆后,我创建了一个分支
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 repo之外的某个位置,然后执行git checkout notebook-file
来获取在发生分歧的父节点中的文件。对吧?然后,如果我执行git pull ...
就不应该有问题(然后我可以包括那个复制文件的更改)
但是......
我又一次遇到了合并冲突错误。我变得疯狂,尝试了几种方法,但仍然无济于事。
我在下面附上了 git log。 我所说的分支是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>
来解决它时。被蓝色曲线包围的部分是合并的地方,我不知道这里发生了什么(我的意思是,我无法完全记住我疯狂时使用的确切git命令)。
请问有人能帮助我或指导我是否有任何遗漏的东西吗?
git show :1:that.file > that.file.common
命令获取了该共同文件的副本,并将其合并到其中一个分支中,然后手动添加更改。git diff 命令很好用,但它显示了笔记本的许多元数据更改,这使得对我来说很难处理。 - Nima S