7

I have had the issue currently where I needed to remove my .git/index.lock file. Without too much hesitation I am guessing that this file somehow locks processes that can access the git repo. However I can't seem to find a good description/documentation for what this file actually does and why you get the problem described for instance in this question(link).

What does the index.lock actually do, and what causes the problem that people are having related to this file?

It would be very nice to know so I can prevent this issue in the future.

Community
  • 1
  • 1
Automatico
  • 12,420
  • 9
  • 82
  • 110

1 Answers1

6

I have found this from https://www.kernel.org/pub/software/scm/git/docs/technical/api-lockfile.html. This tells you what .git/index.lock does.

  • Mutual exclusion. When we write out a new index file, first we create a new file $GIT_DIR/index.lock, write the new contents into it, and rename it to the final destination $GIT_DIR/index. We try to create the $GIT_DIR/index.lock file with O_EXCL so that we can notice and fail when somebody else is already trying to update the index file.
  • Automatic cruft removal. After we create the "lock" file, we may decide to die(), and we would want to make sure that we remove the file that has not been committed to its final destination. This is done by remembering the lockfiles we created in a linked list and cleaning them up from an atexit(3) handler. Outstanding lockfiles are also removed when the program dies on a signal.

I guess the reason of the problem you said is malfunction of the Automatic cruft removal on some OS. I have used Git on Linux since a few years ago, but not experienced such kind of problem yet.

npcode
  • 1,370
  • 1
  • 14
  • 29