I use Git for version control.
Recently, after committing in Git, the .lock file used to lock HEAD keeps remaining(.git/HEAD.lock).
Git process is dead, and I can use rm to remove the HEAD.lock file.
If you commit with HEAD.lock still intact, Git will crash with an error.
It was working fine until I committed 50, but since then it has been behaving strangely.
This problem does not completely prevent committing, but it does make it problematic to run rm .git/HEAD.lock
every time before committing.
I have run git update-git-for-windows
since this problem occurred, but I continue to have this problem multiple times.
Log:
04:12:11.966: [SameProject] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false add --ignore-errors -A -f -- path/to/file.file path/to/file2.file path/to/file3.file
04:12:12.415: [SameProject] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false commit -F C:\Users\UserA\AppData\Local\Temp\git-commit-msg-.txt --
fatal: cannot lock ref 'HEAD': Unable to create 'C:/path/to/.git/HEAD.lock': File exists.
Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.
The commands was run from IntelliJ IDEA, and I thought IDEA was causing something, but looking at the command, I don't think so.
I'm a noob when it comes to git, but I'm thinking that index or config in the .git directory got corrupted somehow, but I don't remember doing a force push or force quit.
I just tried to commit and had the same problem again. At that time, there was a disturbing log in the Git log.
04:37:56.500: [SameProject] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false add --ignore-errors -A -f -- path/to/fileC.file
04:37:56.585: [SameProject] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false commit -F C:\Users\UserA\AppData\Local\Temp\git-commit-msg-.txt --
warning: unable to unlink 'C:/path/to/.git/HEAD.lock': Invalid argument
I am using a translator. Thank you.
CodePudding user response:
Try first the same sequence, form IntelliJ IDEA, right adter a reboot, in order to minimize the presence of other processes which might keep an handle on that HEAD.lock
file.
HEAD.lock
is still an issue with current versions of Git for Windows, as shown in issue 2531 and commit 3c769b9.
If this still fails after reboot, close IntelliJ IDEA, and try a commit from command-line, to see if the issue persists.
The OP Peyang concludes in the comments:
I didn't know there was an issue.
If I rungit
from the command line, it still fails to Unlink, but asks if I want to retry, and if I runy
, it completes the commit successfully.