Git config alias doesn't work anymore

2020-07-10 09:03发布

问题:

I used command:

git config --global alias.st status

to add my first alias as suggested by post - How do I alias commands in git?

Then, I found it being added to config file at:

C:\Users\damodar.bashyal\.gitconfig

So, i added bunch of aliases directly on the config file and all worked perfectly until today when I had to restart my computer after installing MYOB software.

When i tried to use alias none worked. So, i added another alias using above command, but the file didn't get updated but new alias worked fine.

So after struggling for a while found a command at [ Where does git config --global get written to? ] to look for the config file:

git config --global --edit

To my surprise, it was showing different location with new git alias added in it.

.gitconfig(~) - VIM

[gui]
   recentrepo = C:/_projects/example.com/trunk/bitbucket
[user]
   name = damu
[alias]
   st = status

Is there a way to change back path to previous .gitconfig file?

I am using windows 7 and msysgit.

c:\>echo %HOME%
%HOME%

c:\>set HOME
HOMEDRIVE=U:
HOMEPATH=\
HOMESHARE=\\agsbs\UserShares\Damodar.Bashyal

c:\>echo %HOME%
%HOME%

UPDATE: followed this post [ Change User location(home variable) in Egit (Eclipse) ] to set missing HOME environment variable and now i am getting this:

c:\>set HOME
HOME=C:\Users\damodar.bashyal
HOMEDRIVE=U:
HOMEPATH=\
HOMESHARE=\\agsbs\UserShares\Damodar.Bashyal

That also fixed my issue. YAY!!!

回答1:

Check what your HOME references:

echo %HOME%
# or
set HOME

git config --global will reference the HOME path (unless you would use the --file option).
HOME isn't defined by default on Windows, but it is set by the git-cmd.bat script included with msysgit.

@if not exist "%HOME%" @set HOME=%HOMEDRIVE%%HOMEPATH%
@if not exist "%HOME%" @set HOME=%USERPROFILE%