我只想記錄這個問題,它是由 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
uj5u.com熱心網友回復:
問題是您將 Git 資料存盤在由云同步服務管理的目錄中。Git 要求檔案系統具有確定性行為,特別是 POSIX 設定的行為。但是,當您使用這種型別的云同步服務時,同步工具可能會修改作業目錄或.git目錄的內容,而這些內容并不反映 Git 所做的事情。因此,您最終可能會遇到鎖定檔案重新出現、操作失敗(因為它們的鎖定檔案已被洗掉或正在使用)或重復檔案等問題。
眾所周知,使用云同步服務會并且確實會導致資料丟失。 Git 以特定順序將檔案寫入磁盤以保持存盤庫的一致性,如果它們未完全同步到另一臺機器或在存盤庫更改時,存盤庫可能會損壞。 Git 維護者強烈建議不要這樣做,未來版本的 Git 常見問題解答將明確指示用戶不要這樣做。
uj5u.com熱心網友回復:
這個問題是由 git 和 Dropbox 之間的不兼容引起的。當用戶創建提交,然后在 Dropbox 仍在重新索引和更新云上的目錄時立即執行推送時,Windows 10 將不允許 WSL 上的 Ubuntu 在 Dropbox 訪問檔案夾時洗掉鎖定檔案。
解決方法是:
1)手動洗掉鎖定檔案:
rm /home/<local_repo>/repo/.git/refs/remotes/origin/main.lock
2)等待Dropbox重新索引目錄(觀察任務欄上的dropbox圖示);
3) git push再次。
4) 從 Dropbox 或其他云存盤服務同步的任何檔案夾中洗掉 git 管理的存盤庫, 如下 bk2204 詳述。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/405526.html
標籤:
