作为小型 Web 应用程序的一部分,我对 SQLite DB 进行版本控制。我设置了 clean 和 smudge 过滤器,以便将数据库作为 SQL 而不是二进制存储在远程存储库上,因此我实际上可以在那里读取其条目。
我是如何做到这一点的:
$ git config --global filter.sqlite3tosql.clean "sqlite3 %f .dump"
$ git config --global filter.sqlite3tosql.smudge "sqlite3 %f"
$ echo "*.db filter=sqlite3tosql" > /etc/gitattributes
这在我进行手动提交时有效,但当我从网络应用程序进行编程提交时 -
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
但这对解决问题没有帮助。
最佳答案
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
帐户的配置值,可以通过以 appuser
身份运行 git config ...
命令,或者复制/home/appuser/.gitconfig
的相关部分。
另一个选项是设置 GIT_CONFIG_GLOBAL
环境变量以显式命名要从中读取配置设置的文件:
GIT_CONFIG_GLOBAL=/path/to/config/file git commit
检查git help git
以获得有关这些全局环境变量的详细信息。
关于git - 为什么我的 git clean 和 smudge 过滤器在以编程方式提交时不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70016351/