Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The Repository is Locked - Error while trying to commit into source control

I was trying to commit files into my source control (Git) as usual, using Xcode 7.0.1 and from a point onwards I keep getting this message, disallowing me to commit changes into my source control:

The Repository is Locked

Anyone know how to resolve this?

like image 898
cmario Avatar asked Oct 07 '15 11:10

cmario


People also ask

What is git lock?

When you perform a Git command that edits the index, Git creates a new index. lock file, writes the changes, and then renames the file. The index. lock file indicates to other Git processes that the repository is locked for editing.

How do I lock a git repository?

Lock the branch by selecting the ... icon next to the branch name and then selecting Lock from the menu. A lock icon will appear next to the branch name. Unlock a locked branch by selecting Unlock from the same menu.

Which operation is performed when a file in the local repository is added to the index?

Adding changes to the Index This process is done by the use of git add command. When the changes have been made in the Working Tree/Area. These changes need to be added to the Staging Area for further modification of the file. git add command adds the file in the local repository.


2 Answers

It's just a common issue faced if two or more git operations are done by your system and that generates a lock file.

All you need to do is:

  1. Close Xcode
  2. Open the .git folder in your xcode project folder. The folder is hidden, so you would need to either use terminal to open the directory or the "Go to Folder" option in Finder.
  3. Then delete the "index.lock" file. Either through terminal or Finder.
  4. Try and commit again.
  5. If it fails again, repeat 1 to 3 but commit first with terminal.

If you know what you're doing just typing this command into terminal in the current directory of your project and it should delete the lock file: rm -f .git/index.lock

If anything you can check this Quora question for more details on what you've faced: https://www.quora.com/Why-do-my-git-operations-often-fail-with-a-lock-error

Hope that helps you guys, and happy coding!

like image 100
daliso Avatar answered Sep 30 '22 02:09

daliso


Also make sure the simulator is not running while you are commiting. Close both simulator and Xcode. then restart and try again

like image 43
smoothumut Avatar answered Sep 30 '22 03:09

smoothumut