【发布时间】:2014-01-20 13:27:30
【问题描述】:
将您的 .git/hooks/pre-commit 更改为以下内容:
#!/bin/bash
git status
sleep 10000
更改一些文件,但不要使用git add 暂存它。然后运行git commit -a。
您应该会看到如下内容:
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: somefile.txt
然后它将等待sleep 调用。同时,打开另一个 shell 窗口并运行git status。你应该看到:
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: somefile.txt
不同的 git 调用看到不同的索引,pre-commit 钩子会根据是否使用 -a/--all 调用提交来查看即将提交的索引,但相同的 git 命令在其他 shell 不受影响。
我的问题是 我有一个脚本,当它作为预提交挂钩安装时,它看到的索引就像 git 在另一个 shell 中运行一样,而不是看到预提交挂钩的索引应该看到的。我想让它看到“预提交索引”,或者至少了解索引在不同外壳中看起来不同的工作原理。
脚本做了一些事情(与 vagrant 一起),其中它不会被视为具有相同的父 PID 或环境,也许这是相关的。
更新:可能与 index vs index.lock 有关?
【问题讨论】:
-
还有什么有趣的,在一个shell中运行
git commit -a,尝试进行一些其他更改并在另一个shell中运行git add,索引似乎没有被修改,大喊“.git /index.lock”文件存在。但是在一个 shell 中执行git add; git commit -a,然后在另一个 shell 中git add工作正常(无锁定)。 -
所以它可能使用 .git/index.lock 而不是 .git/index ,反之亦然。我不知道它是如何知道使用哪个或如何指定它以使用其中一个。
标签: git shell unix vagrant githooks