Is it possible to configure user.name and user.email per wildcard domains in .gitconfig?

前端 未结 5 496
不思量自难忘°
不思量自难忘° 2021-01-31 03:00

I have a work computer, and it\'s configured globally to use my work email and name when committing. This is good. However, I\'d like to make some sort of rule that says, \"if t

5条回答
  •  甜味超标
    2021-01-31 03:38

    user.name and user.email are used to "sign" your commits. Since commits are repo-independent (say, the same commit will be in lots of different repos when you push them), those properties are not remote-dependent.

    What you can do is to set different logging's when connecting to different remotes via https. You would just put the username in the url, in the form https://username@host/path/to/repo.git and you're done.

    But the commit author's will be the same user.name, because commits are made locally, and then just shared with others.

    As the commiter's identity is part of the commit, if you make two commits that are the same except for the commiter's name and email, those commits would have different hashes, so they'll be two different commits to git at all. That would be a mess :)

    If you really want to do this, maybe you can make something with hooks that pushes your commits to another repo on your computer, and that other repo (via hooks, again) will re-write the commits, change the author, and push to the other remote.

    But it's so nasty I'll deny having told you about that ;)

提交回复
热议问题