Can `git config` override entries in .gitconfig?

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Can `git config` override entries in .gitconfig?

From: Nicholas LaRoche <hidden>
Date: 2016-06-15 22:45:49

Is there a direct way to change the user.email entry for a git 
repository for one user (applied to all previous commits)?

I tried `git config --unset user.email` followed by `git config 
user.email email2` but it just sets a second field called user.email 
that shows up in `git config -l` as a duplicate. My ~/.gitconfig file 
contains email1 for the user.email entry.

Also, when the repository is created can I specify a second set of 
contact information (i.e. using a project specific email) which isn't a 
part of ~/.gitconfig?

output of `git config -l`:
user.email=email1
..
..
user.email=email2

Regards,
Nick

Re: Can `git config` override entries in .gitconfig?

From: Johan Herland <hidden>
Date: 2016-06-15 22:45:49

On Tuesday 23 December 2008, Nicholas LaRoche wrote:
Is there a direct way to change the user.email entry for a git
repository for one user (applied to all previous commits)?

I tried `git config --unset user.email` followed by `git config
user.email email2` but it just sets a second field called user.email
that shows up in `git config -l` as a duplicate. My ~/.gitconfig file
contains email1 for the user.email entry.

Also, when the repository is created can I specify a second set of
contact information (i.e. using a project specific email) which isn't a
part of ~/.gitconfig?

output of `git config -l`:
user.email=email1
..
..
user.email=email2
Hi,

Use git-config's --global option to set options in your ~/.gitconfig. 
Otherwise, your config changes are stored in the current repo's config 
(.git/config).

In your case, when you did `git config --unset user.email`, you unset the 
(non-existing) user.email in your repo config, without touching the one in 
~/.gitconfig, and when you did `git config user.email email2`, you set 
user.email in the repo config (without changing the one in your 
~/.gitconfig).

Although `git config -l` displays options from both ~/.gitconfig and the 
repo config, AFAIK the repo config does _override_ the ~/.gitconfig, so 
when you have user.email set in both, your new commits will use the one in 
the repo config (i.e. "email2").

As for rewriting your email address in all previous commits, that is 
impossible to do without rewriting your entire history. Rewriting your 
history is probably not something you want to do if you have published your 
repo, and other people have started working on top of your commits. If you 
_do_ want to rewrite your history, you should look at the "git 
filter-branch" command.


Have fun!

...Johan

-- 
Johan Herland, [off-list ref]
www.herland.net
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help