Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git commit command hangs indefinitely

Tags:

git

git-commit

When I tried to make a commit using git commit, the sublime text editor did open, I wrote the commit message and saved and closed the editor but the changes were not being committed. The terminal hanged at the git commit.

I searched the net and found someone with the same issue and applied the same fix without thinking anything. I ran the command:

git config --global core.editor "mate -w" 

and now I have a new error when I run git commit:

mate -w: 1: mate -w: mate: not found error: There was a problem with the editor 'mate -w'. Please supply the message using either -m or -F option.

Please help. I am very new with git and using Ubuntu 14.04.

like image 777
user2715898 Avatar asked Feb 02 '15 10:02

user2715898


1 Answers

Git runs a lot of external bits as part of a commit. While Git itself is unlikely to hang, any of the external parts it calls could, so in order of execution:

  1. The pre-commit hook. This is a script at $REPO_ROOT/.git/hooks/pre-commit (it is not the .sample file! It has to be one named, exactly and only, pre-commit.) Check the contents of the script to see if it might hang.
  2. The prepare-commit-msg hook. It's right next to the pre-commit hook, named like you'd expect. Same thing.
  3. If you didn't pass -m, then your editor starts so you can input the message. Make sure that
    • The window isn't hidden somehow (offscreen, minimized, behind other windows)
    • The editor itself isn't hanging
  4. The commit-msg hook. Same as the other hooks.
  5. Commit signing. This step only runs if you specify -S with git commit, or if you have commit.gpgsign = true. You can check the latter with git config commit.gpgsign. This also depends on your GPG agent. Check:
    • If your agent uses a GUI to get your passphrase, the window isn't hidden, like with the editor.
    • The agent itself isn't hanging. I've had several issues with mine, a curses-based one, hanging.
    • You can always kill your GPG agent. All it does is save your password briefly, so you don't need to enter it every time. When you git commit again, it'll start fresh; this may or may not help with your hanging.
  6. The post-commit hook.

Note that I've only addressed manually creating commits. merge will also create commits, and it follows largely the same sequence, with some different hooks.

In addition, Git itself can take a while if your repo is particularly large -- each commit is essentially a snapshot of all the files in it at a given time. If you judiciously use .gitignores to ignore things like built executables and just track the source code in your Git repo, it can help a lot. Note that this will break some editors: Visual Studio, in particular, is poorly designed and incompatible with Git as a result.

like image 162
Nic Avatar answered Sep 20 '22 19:09

Nic