Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging throws fatal: refusing to merge unrelated histories Git error #874

Closed
nelsonni opened this issue Jul 25, 2022 · 3 comments · Fixed by #946
Closed

Merging throws fatal: refusing to merge unrelated histories Git error #874

nelsonni opened this issue Jul 25, 2022 · 3 comments · Fixed by #946
Assignees
Labels
bug Bug reports or bug fixes

Comments

@nelsonni
Copy link
Member

nelsonni commented Jul 25, 2022

Describe the bug
When merging linked-worktree branches within the EPICLab/ant-design, specifically task-1-base and task-1-compare, the merge is not initiated and instead throws:

fatal: refusing to merge unrelated histories

To Reproduce
Steps to reproduce the behavior:

  1. Launch Synectic
  2. Go to FileOpen...
  3. Select the root directory of a repository with a base branch that reside in a linked worktrees
  4. Go to ActionMerge...
  5. Select the Repository from the drop-down menu
  6. Select Base that resides in the linked worktree and Compare branches from the drop-down
  7. Select the Merge button
  8. Wait for the merge process to complete
  9. See error

Expected behavior
The merge process should complete with Resolve 1 conflict and commit resolution before continuing. being displayed on the Merge dialog.

Screenshots
image

Versions (please complete the following information):

  • OS: MacOS
  • Synectic Version: 2.3.0
  • git: 2.32.1 (Apple Git-133)

Additional context
Related to merging issues in #831.

@nelsonni nelsonni added the bug Bug reports or bug fixes label Jul 25, 2022
@nelsonni nelsonni self-assigned this Jul 25, 2022
@nelsonni
Copy link
Member Author

Based on the article, How to fix ‘fatal: refusing to merge unrelated histories’ Git error:

The fatal: refusing to merge histories error is a fairly common Git error. It appears when a developer tries to merge two unrelated projects into a single branch.

This error appears when the branch has its commit histories and tags incompatible with the pull request or clone.

@nelsonni
Copy link
Member Author

This issue does not occur on my system, but does on @pannapat's MacOS system. After further investigation, it appears that the .git file is not created in the task-1-base linked worktree directory:
image

@nelsonni
Copy link
Member Author

This issue appears to be related to the process of adding new linked worktrees (via git-worktree.add()) during the merge process (via merges.merge(), which calls git-porcelain.checkout().

The initial fix involves switching away from using isomorphic-git commands and directly calling git worktree add {worktreeDir} {branch} instead. However, this can still result in the fatal: refusing to merge unrelated histories error. Attempting to do these steps in the terminal (and bypassing Synectic) shows the following different error:

projects/ant-design:~ (master) $ git merge task-1-base task-1-compare
fatal: refusing to merge unrelated histories

projects/ant-design:~ (master) $ git worktree remove task-1-base

projects/ant-design:~ (master) $ git branch -d task-1-base
warning: deleting branch 'task-1-base' that has been merged to
         'refs/remotes/origin/task-1-base', but not yet merged to HEAD.
Deleted branch task-1-base (was e199a7a30).

@nelsonni nelsonni mentioned this issue Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug reports or bug fixes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant