【发布时间】:2022-01-07 11:42:11
【问题描述】:
我只想记录这个问题,它是由 git 和云同步服务之间的不兼容引起的。应避免将存储库存储在与 Dropbox 同步的文件夹中。
在装有 Windows 10 和 Windows Subsystem for Linux 的机器上,如果用户在 Dropbox 管理的目录中有 git 存储库,则在尝试 git push 最近提交时可能会出现以下错误:
warning: unable to unlink '/home/<local_repo>/repo/.git/refs/remotes/origin/main.lock': Permission denied
error: update_ref failed for ref 'refs/remotes/origin/main': couldn't set 'refs/remotes/origin/main'
此外,在git status 上,即使远程已更新,存储库也会显示在远程之前:
$ git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
进一步推送可能会出现File exists 错误(但是,提交已成功推送到远程):
$ git push
error: update_ref failed for ref 'refs/remotes/origin/main': cannot lock ref 'refs/remotes/origin/main': Unable to create '/home/<local_repo>/.git/refs/remotes/origin/main.lock': File exists.
Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.
Everything up-to-date
【问题讨论】:
-
您不认为在 Dropbox 目录中“托管”一个 git 存储库,说实话,是一种反模式,可能会导致您的 git 存储库损坏并让您的数据丢失?跨度>
-
@fluffy 是的,有点。 :) 为了扩展,我通常不会这样做,但显然我只是因为软链接了父文件夹而做了。我花了一点时间才意识到这个问题,所以我想我会把它写下来。
-
切勿将 Git 存储库存储在任何云同步文件夹中。云同步软件总是不可避免地最终会损坏 Git 存储库。根据墨菲定律,这种损害会一直等到最具破坏性的时刻。 :-)
标签: git dropbox windows-subsystem-for-linux