作為小型 Web 應用程式的一部分,我對 SQLite DB 進行版本控制。我已經設定了清理和涂抹過濾器,以便將資料庫作為 SQL 而不是二進制存盤在遠程存盤庫上,因此我實際上可以在那里讀取其條目。
我是如何做到這一點的:
$ git config --global filter.sqlite3tosql.clean "sqlite3 %f .dump"
$ git config --global filter.sqlite3tosql.smudge "sqlite3 %f"
$ echo "*.db filter=sqlite3tosql" > /etc/gitattributes
這在我進行手動提交時有效,但是當我從 Web 應用程式進行編程提交時——
subprocess.call("git add /home/appuser/repo/db.db", shell=True)
subprocess.call("git commit -m 'update db'", shell=True)
subprocess.call("git push origin master", shell=True)
– 過濾器以某種方式被忽略。提交和推送成功,但 SQLite 存盤為二進制檔案。
我在這里錯過了什么?
為了徹底,這里是 gitattributes 檔案的權限:
$ ls -l /etc/gitattributes
-rw-r--r-- 1 root root 25 Nov 18 07:27 /etc/gitattributes
我的用戶屬于 sudoers,該應用程式使用我的用戶和組(不是 root)通過 systemd 和 gunicorn 運行。我git config --global以我的用戶身份運行呼叫 - 不是 root 或應用程式用戶。
我也試過
$ echo "*.db filter=sqlite3tosql" > ~/.config/git/attributes
$ echo "*.db filter=sqlite3tosql" > /home/appuser/.config/git/attributes
$ ls -l ~/.config/git/attributes
-rw-r--r-- 1 myuser www-data 25 Nov 18 07:55 /home/myuser/.config/git/attributes
$ ls -l /home/appuser/.config/git/attributes
-rw-r--r-- 1 myuser www-data 25 Nov 18 07:55 /home/appuser/.config/git/attributes
但這對情況沒有幫助。
uj5u.com熱心網友回復:
git config --global ... 表示對運行命令的用戶帳戶是全域的,而不是系統
用戶的默認“全域”組態檔appuser是/home/appuser/.gitconfig,
但如果您運行:
$ git config --global filter.sqlite3tosql.clean "sqlite3 %f .dump"
$ git config --global filter.sqlite3tosql.smudge "sqlite3 %f"
使用您自己的用戶帳戶,這些設定已寫入您自己的/home/youruseraccount/.gitconfig檔案。
appuser通過將git config ...命令作為運行appuser,或通過將相關部分復制到 來設定帳戶的配置值/home/appuser/.gitconfig。
另一種選擇是設定GIT_CONFIG_GLOBAL環境變數以顯式命名檔案以從中讀取配置設定:
GIT_CONFIG_GLOBAL=/path/to/config/file git commit
檢查git help git以獲取有關這些全域環境變數的詳細資訊。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/360085.html
