Issue
Some background story!
I have been working with git to contribute to an open source package, and I am somewhat novice in this area. I know some basic stuff. Furthermore, I also read that if merge conflict happens, we can go through the file and the markers can help us to find the block of codes that have conflict with each other in two versions of the same file.
Recently, I confronted a merge conflict for the first time, and it is on Jupyter notebook file (.ipynb). However, the markers of merge conflict make the notebook unreadable by Jupyter. So, I tried JSON editor and VS CODE and Notepad++. Although I can now see the file, it is really messy because it not only has all metadata of Jupyter notebook but also it shows conflict even for the number of execution. In addition, if there is a figure as an output of a cell in the notebook, it is converted to a lot of characters and scrolling down and go through them is headache.
After searching google and stackoverflow and discuss the issue with the owner of the project, we decided to take another approach. But, it doesn't work. (I explained it below, but first I need to provide further info. Please bear with me)
According to the history of the commits, I should be the one who created such conflicts locally by probably changing the same file on the PARENT branch as nobody changes it in the upstream (in the originAL repo)
Therefore, please let me first briefly walk you through the branches and some changes I did on files.
- After forking and cloning, I created a branch
branch-A
- I changed the notebook 'notebook-file`
- I did Pull Request (PR)
- I created a sub-branch of A, lets call it
sub-branch-of-A
- After switching to sub-branch, I changed two .py files and then also change that
notebook-file
- merge
sub-branch-of-A
intobranch-A
Inside my branch-A
, I did: git push origin branch-A
but I got non-fast-forward
error. Which means a divergence happened. Right? So, I did git pull origin branch-A
to resolve it, but I get merge conflict for the notebook-file
.
Alternative Solution
So, I was told that I can copy the file to somewhere outside my local git repo, then do git checkout notebook-file
to get the file in the parent node where divergence happened. Right? Then, if I do git pull ...
there should be no problem (then I can include the changes of that copied file)
BUT...
I, again, got the merge conflict error. I went crazy and tried several things and still nothing.
I attached the git log below.
The branch I am talking about is Snippets_Tutorial
, And its sub-branch is Snippets_Regime
. If I remember correctly, I used git checkout -b Snippets_Regime Snippets_Tutorial
to create that sub-branch. As I mentioned earlier, I switched to the sub-branch Snippets_Regime
and did some changes to somefile.py
files and the notebook-file
. Then, I merge it into 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
:
I am attaching the same thing but in image format as I need to highlight two commits:
The highlighted commit at the bottom of the image is the one that I can see in the fork.
The other highlighted commit is when I thought I can resolve it by doing git merge main <branch>
while I am at that <branch>
. The part enclosed by a blue curve is where things got merged and have no idea what's happening here (I mean, I cannot completely remember the exact git commands I used when I went crazy)
Could anyone please help me / guide me if there is something that I am missing?
Solution
What matters in a merge conflict resolution is the two tips and the base, and the conflict. Everything else is noise.
git diff :1:that.file :2:that.file
git diff :1:that.file :3:that.file
will show you the two sets of changes git's merging. In almost all cases that's identical to git diff MERGE_HEAD... that.file
and git diff ...MERGE_HEAD that.file
, it's only when Git's resolving unusual differences introduced by previous criss-cross merges, i.e. multiple equivalent merge bases with different content, not something you see in most histories, that the base content isn't from a single existing base commit.
Answered By - jthill
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.