簡體   English   中英

提交前掛鈎解決方案

[英]Pre commit hook solution

我正在尋找一個解決方案,在此之前我先確定要推送到的主機,然后再更改為適當的git用戶。 例如,如果我要推動一個位桶,那么我應該使用

example@bitbucket.com

如果推到git,那么我應該使用

example@github.com. 

鏈接到類似的解決方案或只是高級方法。 當前,我有一個switch_user bash腳本,可用於在用戶名之間切換,但是我忘了這個。

github的幫助頁面之后 ,您可以使用git config user.email "email@example.com"設置您在git存儲庫中提交的電子郵件。 缺少--global標志使得它僅適用於此特定存儲庫。

如果要為添加的新項目自動執行此操作,建議添加一個git別名腳本來為您解決。 git smart-clonegit smart-remote-add

所以我發現我實際上可以做一個全局鈎子

在您的全局gitconfig ,可以在這里找到

$ vi ~/.gitconfig

編輯core.hookspath

hookspath=/path/to/git-hooks

然后我做了這樣的事情

#!/bin/sh

File=$PWD/.git/config

if grep -q github.com "$File"; then
    git config --global user.name "Foo Bar"
    git config --global user.email example@github.com
else
    git config --global user.name "Bar Foo"
    git config --global user.email example@bitbucket.com
fi

git commit nom_rep
git push nom_rep或fichier //倒入ajouter les fichier git狀態

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM