Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 331890

Summary: Branch is lost after commit
Product: [Technology] EGit Reporter: Jens Baumgart <jens.baumgart>
Component: CoreAssignee: Jens Baumgart <jens.baumgart>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3 CC: sop
Version: 0.10.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Jens Baumgart CLA 2010-12-06 07:38:09 EST
I tried to commit my last change. The commit failed and my local branch is gone with all my changes.
The error in the log:
!ENTRY org.eclipse.egit.ui 4 0 2010-12-03 16:42:49.023
!MESSAGE Committing failed
!STACK 1
org.eclipse.team.core.TeamException: Failed to update HEAD to commit AnyObjectId[6e24cb7ec8a73746e515f49be833eb18911eb165].
        at org.eclipse.egit.core.op.CommitOperation.doCommits(CommitOperation.java:344)
        at org.eclipse.egit.core.op.CommitOperation.access$8(CommitOperation.java:281)
        at org.eclipse.egit.core.op.CommitOperation$1.run(CommitOperation.java:178)
        at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1800)
        at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1782)
        at org.eclipse.egit.core.op.CommitOperation.execute(CommitOperation.java:192)
        at org.eclipse.egit.ui.internal.actions.CommitActionHandler$1.run(CommitActionHandler.java:187)
        at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
!SUBENTRY 1 org.eclipse.team.core 4 0 2010-12-03 16:42:49.023
!MESSAGE Failed to update HEAD to commit AnyObjectId[6e24cb7ec8a73746e515f49be833eb18911eb165].
 
What I have done:
        
1.	EGit version 0.9.3
2.	I had local branch different then the master.
3.	I changed some files
4.	Team->Commit -> Amend previous commit.
5.	When I tried to commit the error appeared.
6.	Now the local branch is gone – I don’t have active branch at the moment:
7.	At the moment in the log I see NPE – it seems because I don’t have local active branch now and all my files has icon “+”.
Comment 1 Jens Baumgart CLA 2010-12-06 07:47:05 EST
CommitOperation fails in line 343:

if (ru.forceUpdate() == RefUpdate.Result.LOCK_FAILURE) 

We could reproduce the scenario by simulating the following in LockFile.commit

1. Deleting the original file succeeds.
2. Renaming the temporary file fails.

Workaround
==========

1. The commit is not lost. You can create a new branch pointing to it using the command line:

Exit Eclipse
git checkout -b tmpbranch 6e24cb7ec8a73746e515f49be833eb18911eb165
The id of the commit is taken from the error log.

2. Check your .git directory \.git\refs\heads
Is there a file <branchname>.lock and the corresponding file <branchname> is missing? 
If yes: delete branchname.lock.
Comment 2 Jens Baumgart CLA 2010-12-06 07:54:21 EST
Fix proposed: http://egit.eclipse.org/r/2049
Comment 3 Shawn Pearce CLA 2010-12-06 18:56:03 EST
Fix committed to JGit as cbf5ff6ac7762e2b7170edae9d1563ae3869544a