在最近有一個同事問了我一個問題,平常 Git 都是使用私人的 Email 在 Commit,但是公司的專案要用不同的 Mail 要怎麼處理呢?
在這邊教大家兩個方法來達成這件事情
方法一
如果只有一個 commit 需要修改 name 跟 email,推薦使用以下方法:
git commit -m "Commit message" --author "Your Name <email>"
方法二
如果希望以後某個資料夾下面都使用特定的 name 跟 email commit,推薦使用以下方法:
修改 ~/.gitconfig
[includeIf "gitdir:~/github/"] path = ~/github/.gitconfig [includeIf "gitdir:~/work/"] path = ~/work/.gitconfig
修改各個資料夾底下的 .gitconfig
以範例為例子需要修改 ~/github/.gitconfig
與 ~/work/.gitconfig
改成如下:
[user] name = Clarence email = clarence@github.clarence.tw
[user] name = Clarence email = clarence@work.clarence.tw
修改完在對應的資料夾下面 commit 就會是對應的 name 與 email 了!
結論
以上是一些在用 Git 可能會有需求用到的功能,希望有幫助到大家 ~