sluggerdog
sluggerdog

Reputation: 843

GIT: /.git/index.lock': File exists

I am having a constant issue with one of my git repos. I keep getting the following error:

    fatal: Unable to create 'v:/path/to/files/.git/index.lock': File exists.

    If no other git process is currently running, this probably means a
    git process crashed in this repository earlier. Make sure no other git
    process is running and remove the file manually to continue.

I have tried: rm -f ./.git/index.lock as per another thread on stackoverflow but I get this error each time: rm: cannot unlink `./.git/index.lock': Permission denied

When I close down aptana (I am using git in the terminal) I cannot delete the file still.

Any ideas how to get around this?

Another thing to note is this git repo is very slow when I do occasionally get to commit within it (it allows me every 10 tries or so)

Thanks

Upvotes: 19

Views: 58614

Answers (7)

Steve
Steve

Reputation: 133

Be careful with

rm -f .git/index.lock
git reset

Doing a git reset will delete any uncommitted changes that you've made.

Deleting your index.lock will mean that git will not be able to track any local changes.

One alternative for restoring your index.lock could be to git stash your last commit (if it's not yet pushed), and then do a git stash pop to add it back in.

So:

rm -f .git/index.lock
git stash
git stash pop

This will create a new index.lock without doing a git reset.

If you had previously git added some files without committing, you will need to git add those files again.

It's a bit of a hack. Comments?

Upvotes: 1

Harshit Garg
Harshit Garg

Reputation: 2259

In git version 2.11.0, .git folder may not include the index.lock file. I figured out in the .git/refs/heads/ folder contains a .lock file and removing it using rm command works.

Also be sure to kill the process that might be using git repo using ps -aef | grep git and kill -9.

Upvotes: 0

krishnaisdinesh
krishnaisdinesh

Reputation: 391

This may be an old reply but I'm hoping this is more useful on next who need this solution.

On linux/unix/gitbash/cygwin, try

rm -f .git/index.lock

On Windows Command Prompt, try:

del .git\index.lock

Hope that helps, I found this solution here: fatal: Unable to create 'project_path/.git/index.lock': File exists.

Upvotes: 0

SEAFERN
SEAFERN

Reputation: 53

Do this:

rm index.lock

followed by

git reset

Upvotes: 1

Johan Van de Merwe
Johan Van de Merwe

Reputation: 312

You also get this error if you are using Aptanta Git and other git clients, like f.e. TortoiseGit. So it is likely that this other Git software locked your Git, making it unavailable for Aptana.

Upvotes: 1

Christopher
Christopher

Reputation: 44244

Sudo the command:

sudo rm -f ./.git/index.lock

Both errors suggest index.lock is owned by another user. Run the rm as a superuser, then try your commands again. You might also consider setting core.sharedRepository to true if that is, in fact, the case with your repo:

core.sharedRepository

When group (or true), the repository is made shareable between several users in a group (making sure all the files and objects are group-writable).

When all (or world or everybody), the repository will be readable by all users, additionally to being group-shareable. When umask (or false), git will use permissions reported by umask(2). When 0xxx, where 0xxx is an octal number, files in the repository will have this mode value. 0xxx will override user's umask value (whereas the other options will only override requested parts of the user's umask value). Examples: 0660 will make the repo read/write-able for the owner and group, but inaccessible to others (equivalent to group unless umask is e.g. 0022). 0640 is a repository that is group-readable but not group-writable.

See git-init(1).

False by default.

Upvotes: 32

sluggerdog
sluggerdog

Reputation: 843

The issue ended up being Aptana, everytime I ran this it would cause this error when I tried to commit in git.

I stopped using aptana studio and I don't have this issue anymore.

Upvotes: 4

Related Questions