简体   繁体   English

在 Windows 中更改用户名后控制台中的用户名错误

[英]Wrong username in console after username change in Windows

I had a Windows (Windows 10) local userprofile with an umlaut (ä) in it.我有一个带有变音符号 (ä) 的 Windows (Windows 10) 本地用户配置文件。 With this I got problems while using vagrant in the Git Bash console.有了这个,我在 Git Bash 控制台中使用 vagrant 时遇到了问题。 After some research I changed the username of my local profile (replaced the ä with ae).经过一番研究,我更改了本地配置文件的用户名(将ä 替换为ae)。 I also changed the name of the users folder and reinstalled vagrant after this.在此之后,我还更改了用户文件夹的名称并重新安装了 vagrant。 Everything works fine now except the fact, that the username which is shown in Git Bash is the same as before (with ä in it).现在一切正常,除了 Git Bash 中显示的用户名与以前相同(其中包含 ä)。 But the path is correct (with ae).但是路径是正确的(带有ae)。

I tried to change the username with git config --global user.name but this had no effect on the name displayed.我尝试使用git config --global user.name更改用户名,但这对显示的名称没有影响。 I also reinstalled Git.我还重新安装了 Git。

This is annoying (even tho it has no effect on anything).这很烦人(即使它对任何事情都没有影响)。 Why is that and how can I change it?为什么会这样,我该如何改变它? Is there a way to reset it completely (besides a reinstallation)?有没有办法完全重置它(除了重新安装)?

Because I'm not sure if I use the correct terms I mean this (the bold word) with username:因为我不确定我是否使用了正确的术语,所以我的意思是这个(粗体字)和用户名:

MyNameWithÄ @COMPUTERNAME MINGW64 ~ MyNameWithÄ @COMPUTERNAME MINGW64 ~

And I should also mention that I use Git only locally and I don't know if it even has something todo with Git Bash.而且我还应该提到我只在本地使用 Git,我不知道它是否与 Git Bash 有关系。

Kind regards亲切的问候

If you don't find the proper solution I have one ugly hack in mind.如果你没有找到合适的解决方案,我会想到一个丑陋的黑客。

Git-bash stores it's prompt configuration in /etc/profile.d/git-prompt.sh . Git-bash 将它的提示配置存储在/etc/profile.d/git-prompt.sh When you open that file you should have this line:当您打开该文件时,您应该看到这一行:

PS1="$PS1"'\u@\h '             # user@host<space>

Replacing \\u\u003c/code> here with your name should do the trick.用你的名字替换\\u\u003c/code>应该可以解决问题。 So it would be:所以它会是:

PS1="$PS1"'JohnDoe@\h '             # user@host<space>

In order to see the changes you need to restart git-bash.为了查看更改,您需要重新启动 git-bash。

对于 Windows 10,我发现这与管理员名称和设备名称有关(按 Window + I > Settings > System > About > Device Name)。

Git Bash takes the user from file /etc/passwd. Git Bash 从文件 /etc/passwd 获取用户。 To change it do:要更改它,请执行以下操作:

mkpasswd > /etc/passwd

This step was necessary for me on Windows 10 because the file did not exist in that location.这一步对我在 Windows 10 上是必需的,因为该文件不存在于该位置。 Administrator privileges are necessary (open Git Bash as admin).需要管理员权限(以管理员身份打开 Git Bash)。

Then change the file with your favourite editor (for instance vim).然后使用您喜欢的编辑器(例如 vim)更改文件。 Substitute the old username with the new one.用新用户名替换旧用户名。

Reopen Git Bash to see changes take effect.重新打开 Git Bash 以查看更改是否生效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM