0

Using Eclipse 2022-12 and egit 6.4.0.202211300538-r .

Every once in a while I get a branch in an Eclipse git repository into a state where it appears my only recourse is to delete the entire repository and reclone it to my desktop. This is usually fine if I don't need anything in any of the other branches. Right now, I'm tired of having to do this, so I'm going to pursue this.

I did not initiate a merge, but it thinks I am somehow in the middle of a merge, and either doing a hard reset or doing a "git merge --abort" from the command line doesn't work.

When I do the hard reset and then do a pull, it still thinks there are conflicts. If I select all the files that it think I changed and do "Replace with HEAD", it removes from the staging area, but the git pull still fails and thinks there are conflicts.

I tried "git merge --abort" from the command line, and it says "fatal: There is no merge to abort (MERGE_HEAD missing).".

After I do the hard reset, the repository in the repositories list shows both an uparrow and a downarrow, with "1" next to both of them. I assume that the uparrow indicates there are local changes not pushed, which is odd because I just did the hard reset.

How do I get out of this?

Update:

Answering some questions from comments:

When I run "git status", it says (entirely consistent with what egit tells me):

On branch branchname
Your branch and 'origin/branchname' have diverged,
and have 1 and 1 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

Untracked files:
...

nothing added to commit but untracked files present (use "git add" to track)

I changed the branch name and elided the untracked files.

Also, my pulls are set for merge, not rebase.

David M. Karr
  • 14,317
  • 20
  • 94
  • 199
  • 1
    When this is happening: "but it thinks I am somehow in the middle of a merge", what does `git status` show at that moment? – TTT Feb 15 '23 at 22:28
  • 1
    (This is unlikely to be the problem, but mentioning just in case.... if you have pull configured to rebase instead of merge, you might be stuck in a rebase instead of a merge and you need to do `git rebase --abort` instead of aborting a merge.) – TTT Feb 15 '23 at 22:31
  • AH. I got it. The key was how I was doing the hard reset. The dialog defaults to my local branch, but doing a hard reset to that wouldn't help. Once I changed the hard reset to refer to the remote branch, it cleaned it up. Hopefully I'll remember this the next time. – David M. Karr Feb 15 '23 at 22:42
  • Regarding the update, I'm now confused about what the actual issue is. At that status, you are diverged (1 new commit locally and 1 new commit remotely), and you aren't yet in a merge state. Now you have 3 options: keep only local, keep only remote, or keep both. If you wish to keep both, you can pull (which merges in the remote branch), and if you have conflicts, you resolve the conflicts, and then continue the merge. If you wish to throw away your local changes, you just hard reset to the remote branch. If you wish to throw away the remote changes, you force push. – TTT Feb 16 '23 at 15:07
  • I still don't understand the state I got into, but I've seen this almost identical scenario multiple times. It may have been telling me I had local changes, but I didn't deliberately make changes. Concerning "throw them away" for the local changes, like "replace with HEAD", I DID that, multiple times, and it made no difference. It still resulted in conflicts after the pull. After a real hard reset to the remote repo, it appears to be sane again. Ah, but now that I think about the change I made to how I did the hard reset, I see that "replace with HEAD" just replaced with the local head. – David M. Karr Feb 16 '23 at 15:10
  • That's correct. When you have a clean status like you showed (no pending changes), then `git reset --hard` (no arguments) is equivalent to `git reset --hard HEAD`. And that will have no effect because it just points to your local HEAD which is where you already are. To blow away your local commit and replace it with the remote commit, you instead [reset hard to the remote branch](https://stackoverflow.com/a/61490618/184546). Side note: when you're diverged like that, it may help to inspect both your commit and the remote commit to know why you're diverged, before deciding what to do. – TTT Feb 16 '23 at 15:26

0 Answers0