Git:不要为只读操作创建index.lock [英] Git: do not create index.lock for read-only operations
问题描述
有没有办法强制git不为只读操作创建index.lock,比如 git status
?
我在tmux中显示工作树的状态,每隔几秒更新一次。基本上我解析了 git status --branch --ignored --porcelain
和其他一些命令的输出。问题是,对于大型版本库 git status
可能需要几秒钟才能完成。在那期间,我无法运行任何其他git命令,因为存储库已被锁定。
编辑:
我的tmux系列相关部分的一些图片。从左到右的符号说明:
与远程分支|同步2阶段变化| 1未更改| 5忽略文件| 1藏匿条目:
与远程分支|同步没有改变工作树| 5个忽略的文件:
远程分支由1提交|没有改变工作树| 5个被忽略的文件:
使用GIT_INDEX_FILE环境变量让git使用另一个索引文件是什么?使用HEAD创建一个新的索引文件
GIT_INDEX_FILE = .git / other-index git reset
之后您可以只是
GIT_INDEX_FILE = .git / other-index git status
查找更改。
它的缺点是,如果主索引将被add / rm命令修改,则不会看到真实状态。但至少它会让你发现变化的事实,然后可能做更多的事情来找出真正的区别。
你能否描述更多的你正试图达到的目标?也许我们可以提出一些其他解决方案。
另一个想法。试试这个:
cp .git / index .git / other-index#或者可能只是ln一次,而不是复制每次?
GIT_INDEX_FILE = .git / other-index git status
不确定这是多么可靠。 。如果你在执行 git add / rm
时发生 cp
命令,那么你可能会有损坏的索引文件,显然会失败,但为了您的使用,我相信这已经足够了 - 您可以忽略失败并重试。
Is there a way to force git not to create index.lock for read-only operations like git status
?
I'm displaying the status of my working tree in tmux, being updated every couple of seconds. Basically I parse the output of git status --branch --ignored --porcelain
and a few other commands. Problem is, that for large repositories git status
can take a few seconds to complete. During that time I cannot run any other git commands because the repository is locked.
EDIT:
Here are some pictures of the relevant part of my tmux line. Description for symbols from left to right:
In sync with remote branch | 2 staged changes | 1 unstaged change | 5 ignored files | 1 stash entry:
In sync with remote branch | no changes in working tree | 5 ignored files:
Ahead remote branch by 1 commit | no changes in working tree | 5 ignored files:
What is about using "GIT_INDEX_FILE" environment variable to make the git to use another index file?
So, to create a new index file from HEAD use
GIT_INDEX_FILE=.git/other-index git reset
and after it you could just
GIT_INDEX_FILE=.git/other-index git status
to lookup for changes.
The downside of it, you will not see the real status if the main index will be modified by add/rm commands. But at least it will allow you to detect the fact of a change and then probably do some more stuff to find out the real difference.
Could you also describe more of the goal you are trying to achieve? Probably we could come out with some other solutions.
Another idea. Try this:
cp .git/index .git/other-index # or maybe just "ln" once, rather than copying everytime?
GIT_INDEX_FILE=.git/other-index git status
Not sure how reliable this... in case if cp
command will happen while you are doing git add/rm
, you could have "damaged" index file, and apparently get a failure, but for your use I believe it is good enough - you could just ignore the failure and retry.
这篇关于Git:不要为只读操作创建index.lock的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!