git 每次拉取都会生成一个新的 master.lock 文件

git generating a new master.lock file every time I pull

运行 git windows 10,我在不同的 git 应用程序(git GUI,git UBUNTU shell, git 在终端)。

在我的所有项目和不同的计算机上都是相同的行为,这让我怀疑我的帐户有问题。这个问题是几个月前开始的,在那之前没有任何问题。

git pull                                                                           
error: cannot lock ref 'refs/remotes/origin/master': Unable to create '/mnt/c/users
/simon/Dropbox/Universitet/dark/datorarkitektur/.git/refs/remotes/origin/master.loc
k': 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.                                              
From https://git.cs.umu.se/c18sjn/datorarkitektur                                   
! 7b1722c..c2c55fa  master     -> origin/master  (unable to update local ref)

我删除了位于.git/refs/remotes/origin/master.lock 中的.lock 文件,但每次拉动时都会生成它。我试图删除所有具有集成 GIT 功能的编辑器并终止除一个终端之外的所有进程。

如果我的分支落后,我可以拉(有类似的警告但确实有效)然后推送,但如果我的分支在拉之前领先(因为拉失败),我根本无法推送.推送示例:

git push                                                                           
To https://git.cs.umu.se/c18sjn/datorarkitektur.git                                 
! [rejected]        master -> master (non-fast-forward)                           
error: failed to push some refs to 'https://git.cs.umu.se/c18sjn/datorarkitektur.git'                                                                                 hint: Updates were rejected because the tip of your current branch is behind       
hint: its remote counterpart. Integrate the remote changes (e.g.                   
hint: 'git pull ...') before pushing again.                                        
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

虽然许多人建议将 Git 存储库放入 Dropbox,但 there are problems. From the git-remote-dropbox FAQ...

Why shouldn't I keep my Git repository in Dropbox and let the client sync it?

...The desktop client is not aware of how Git manages it's on-disk format, so if there are concurrent changes or delays in syncing, it's possible to have conflicts that result in a corrupted Git repository. This may be uncommon with the way the timing works out in the single user case, but it's still not safe!

Dropbox 专为同步文件而设计。 Git 不知道这一点。您实际上有多个不协调的用户试图同时使用同一个本地存储库。 Dropbox 可以“同步”Git 存储库文件并损坏存储库。比如可以复活一个锁文件。

git-remote-dropbox 解决了这些问题。

This Git remote helper makes Dropbox act like a true Git remote. It maintains all guarantees that are provided by a traditional Git remote while using Dropbox as a backing store. This means that it works correctly even when there are multiple people operating on the repository at once, making it possible to use a Dropbox shared folder as a Git remote for collaboration.

安装后,不要将 Dropbox 用于已签出的存储库。将您的存储库移出 Dropbox 并移至普通目录,从那里处理您的代码。仅将 Dropbox 用于远程存储库。

使用 dropbox URL.

声明遥控器
git remote add origin "dropbox:///mnt/c/users
/simon/Dropbox/Universitet/dark/datorarkitektur/"

下次推送时,它将在 /mnt/c/users/simon/Dropbox/Universitet/dark/datorarkitektur/ 中创建一个远程存储库。

您可能需要 git fsck 才能摆脱当前状态。然后事情应该会更顺利地进行下去。