Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fix a failed git commit?

Tags:

git

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.

like image 716
mcgrailm Avatar asked Nov 20 '11 02:11

mcgrailm


People also ask

How can you fix a broken commit?

Simply edit the message right on the top line of the file, save, quit and you're done. Now let's say you've got a few commits to fix, or the commit that is broken is a few commits back. This process is a little more complex, but isn't too bad.

How do I fix commit message?

On the command line, navigate to the repository that contains the commit you want to amend. Type git commit --amend and press Enter. In your text editor, edit the commit message, and save the commit.


3 Answers

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

like image 176
Suhail Taj Avatar answered Oct 12 '22 19:10

Suhail Taj


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"
like image 26
Platinum Azure Avatar answered Oct 12 '22 20:10

Platinum Azure


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.

like image 28
VonC Avatar answered Oct 12 '22 18:10

VonC