[英]Is it possible to attach a message to a git commit that will display when pulled?
[英]Is there a way to display a message to an end-user when they commit a file in Git?
當任何人對我的Git存儲庫中的特定文件進行更改時,我想在用戶通過Git CLI提交或推送時向用戶顯示一條消息。
場景:用戶更改了crazycalculations.py
,我想說:“嘿,我注意到您更改了crazycalculations.py。您是否有John in Accounting來查看您的更改?”。 只是向最終用戶友好地提醒他們,他們混亂的文件是在沒有監督的情況下不會混亂的。
關於如何實現此目標的任何建議?
是的,您可以使用git hooks做到這一點。 如果導航到.git/hooks
您將看到可以在特定git事件上運行的shell代碼示例。 檢查.git/hooks/pre-commit.sample
將有一些示例代碼可以使用。
例如,在.git/hooks/pre-commit
的頂部:
if git diff HEAD --name-only | grep -q "crazycalculations.py"; then
echo "Are you sure you want to edit crazycalculations.py?"
sleep 3
fi
說明文件:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.