19

I am new to git and was trying to commit, but I got stuck in what looked like vi which I'm not familiar with. I managed to get out of it, but I think I got out the wrong way because my git status says "changes not staged," but I still can't try again. Could someone tell me what I can do to fix the still hanging process and commit my changes?

here is the error

fatal: Unable to create '/.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.

not i took out the full path

As always thanks for your help.

mcgrailm
  • 16,637
  • 21
  • 80
  • 128
  • 1
    It would be helpful to see the full results of `git status`. – jdl Nov 20 '11 at 02:27
  • 2
    Note that you can change the editor used for commit messages via `git config --global core.editor EDITOR_NAME`, where `EDITOR_NAME` is an executable in your path (or the full path). – Michael Mior Nov 20 '11 at 02:40
  • You might want to see this question on how to change the default editor in git: http://stackoverflow.com/questions/10564/how-can-i-set-up-an-editor-to-work-with-git-on-windows – yasouser Nov 20 '11 at 03:34
  • 3
    rm -f ./.git/index.lock This worked for me, http://stackoverflow.com/questions/7860751/git-fatal-unable-to-create-path-my-project-git-index-lock-file-exists – RAJCHOW Jun 06 '12 at 11:31
  • @RAJCHOW that worked for me too. I'd "stopped" another git add -a process with CTR+Z – ProfNandaa Oct 24 '14 at 01:07

4 Answers4

13

Removing index.lock file manually from .git directory worked.

or

From command line:

$ rm -rf .git/index.lock

Note: Make sure that only one index file exist on .git directory

Suhail Taj
  • 566
  • 5
  • 6
11

Assuming you're not doing anything with git at the moment (i.e., not doing a push or pull or running a git script in the repository, for any reason), you could just remove the lock file manually and try again.

Also, git expects a "commit message" describing your changes. Assuming you don't want an editor to open, you can provide an inline message using the -m option:

git commit -am "Changed this, that, and the other thing"
Platinum Azure
  • 41,456
  • 9
  • 100
  • 130
1

Note the message will improve and be more explicit with git 2.9 (June 2016), in order to invite you to consider all the causes before removing that lock yourself.

See commit aed7480, commit 3030c29 (01 Mar 2016) by Matthieu Moy (moy).
Helped-by: Moritz Neeb (zormit).
(Merged by Junio C Hamano -- gitster -- in commit 3b8c4b7, 03 Apr 2016)

lockfile: improve error message when lockfile exists

A common mistake leading a user to see this message is to launch "git commit", let the editor open (and forget about it), and try again to commit.

The previous message was going too quickly to "a git process crashed" and to the advice "remove the file manually".

This patch modifies the message in two ways:

  • first, it considers that "another process is running" is the norm, not the exception,
  • and it explicitly hints the user to look at text editors.

The message is 2 lines longer, but this is not a problem since experienced users do not see the message often.

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
1

mine was solved with both answers from Platinum Azure then Suhail Taj

git commit -am "Changed this, that, and the other thing"

Then

$ rm -rf .git/index.lock
Mina Gabriel
  • 17,138
  • 23
  • 89
  • 118