git命令 带用户名密码_Git Config命令教程–带有用户名,密码,电子邮件,别名示例...

git命令 带用户名密码

git命令 带用户名密码

Git is a Source Code Management (SCM) tool which is used by a lot of developers. Git is the most popular SCM against SVN, Mercurial, CVS, etc. Git provides a lot of features and related configuration. Git is designed to be flexible with different configurations. git config command provides different usages like changing user name, email address, coloring, HTTP proxy, alias, etc.

Git是许多开发人员使用的源代码管理(SCM)工具。 Git是针对SVN,Mercurial,CVS等的最受欢迎的SCM。Git提供了许多功能和相关配置。 Git被设计为具有不同配置的灵活性。 git config命令提供了不同的用法,例如更改用户名,电子邮件地址,颜色,HTTP代理,别名等。

git config命令帮助信息 (git config Command Help Information)

We can print git config help information in different ways. One way is running git config command without any option. Another way is using the -h option which will provide the same short help.

我们可以用不同的方式打印git config帮助信息。 一种方法是不带任何选项运行git config命令。 另一种方法是使用-h选项,它将提供相同的简短帮助。

$ git config

OR

要么

$ git config -h
Git Config Help
Git Config Help
Git Config帮助

We can also print more detailed help or all options provided by git with the  --help option like below.

我们还可以使用--help选项打印更详细的帮助或git提供的所有选项,如下所示。

$ git config --help
Git Config Detailed Help
Git Config Detailed Help
Git Config详细帮助

Git配置级别(Git Configuration Levels)

Before starting the usage and examples with the git config command we should learn some basics about git configuration levels. There are 3 level git configuration files that are used in a hierarchical manner. They are named as local , global and system configurations.

在使用git config命令开始使用和示例之前,我们应该学习一些有关git配置级别的基础知识。 有3个级别的git配置文件以分层方式使用。 它们被命名为localglobalsystem配置。

本地 (Local)

The Local Configuration file is related to the given project. The local configuration file is stored in the project folder under the .git with the name of config. Local Configuration is used only on the given project and does not interfere with the other projects. We use --local option in order to specify, change, set, unset, and manage local configuration. If the same setting is defined in the Local, Global, or System configuration the Local configuration setting is used. This means Local configuration is the most preferred configuration in the git config configuration files.

本地配置文件与给定项目相关。 本地配置文件存储在项目文件夹中.git ,名称为config 。 本地配置仅在给定项目上使用,不会干扰其他项目。 我们使用--local选项来指定,更改,设置,取消设置和管理本地配置。 如果在本地,全局或系统配置中定义了相同的设置,则使用本地配置设置。 这意味着本地配置是git config配置文件中最优选的配置。

全球 (Global)

The Global Configuration file is used for the current system user. All projects belong to the current system user will use this Global Configuration file. The Global configuration file is stored under the user home directory in the .gitconfig file. If the same setting is defined in Global and System configuration Global configuration setting is used.

全局配置文件用于当前系统用户。 属于当前系统用户的所有项目都将使用此全局配置文件。 全局配置文件存储在.gitconfig文件中的用户主目录下。 如果在全局和系统配置中定义了相同的设置,则使用全局配置设置。

系统 (System)

The System Configuration file is the most generic git configuration which is used by all users and all projects. It is stored in the /etc/gitconfig file. The system-level configuration has less preference according to the Global and Local configuration. If there is the same configuration in the Global or Local configurations the System level configuration will be omitted.

系统配置文件是所有用户和所有项目使用的最通用的git配置。 它存储在/etc/gitconfig文件中。 根据全局和本地配置,系统级配置的首选项较少。 如果全局或本地配置中存在相同的配置,则将省略系统级别的配置。

配置文件位置/路径 (Config File Location/Path)

Git configurations are stored ina plain text file which can be easily read with a text editor like vim, nano, notepad++, or print to the console with the cat command.

Git配置存储在纯文本文件中,可以使用诸如vim,nano,notepad ++之类的文本编辑器轻松读取,也可以使用cat命令将其打印到控制台。

本地配置文件路径 (Local Config File Path)

The configuration file for the given project is stored in the .git directory of the project with the name of config. This configuration file is only used for the current project.

给定项目的配置文件存储在项目的.git目录中,名称为config 。 此配置文件仅用于当前项目。

Config File Location/Path
Config File Location/Path
配置文件位置/路径

全局配置路径(Global Config Path)

There are also two more configuration levels like global which is used for the current system user and system-wide which will be used for all users in the system.

还有另外两个配置级别,例如用于当前系统用户的全局配置级别和将用于系统中所有用户的系统范围配置级别。

$ cat /home/ismail/.gitconfig
Global Git Configuration File
Global Git Configuration File
全局Git配置文件

系统配置路径(System Config Path)

And the system-wide configuration file is stored in the /etc/gitconfig. But keep in mind that in order to change the system-wide configuration file we need root privileges.

系统范围的配置文件存储在/etc/gitconfig 。 但是请记住,为了更改系统范围的配置文件,我们需要root特权。

$ cat /etc/gitconfig
System Git Configuration File
System Git Configuration File
系统Git配置文件

列出所有配置(List All Configuration)

As there are 3 level configuration files and some have a preference to others listing them one by one and understanding configuration is a daunting task. We can list the generall configuration which is generated by merging all 3 configurations levels with the --list option like below.

由于存在3个级别的配置文件,有些优先选择其他配置文件,因此要理解配置是一项艰巨的任务。 我们可以列出通过将所有三个配置级别与--list选项合并而生成的通用配置,如下所示。

$ git config --list
List All Configuration
List All Configuration
列出所有配置

列出本地配置(List Local Configuration)

We can list Local Configuration of the Git by using both  --list and --local options like below.

我们可以使用--list--local选项(如下所示)列出Git的本地配置。

$ git config --list --local
List Local Configuration
List Local Configuration
列出本地配置

列出全局配置(List Global Configuration)

We can list Global Configuration which is user wide configuration with the --list and --global options like below.

我们可以使用--list--global选项列出全局配置,它是用户范围的配置,如下所示。

$ git config --list --global
List Global Configuration
List Global Configuration
列出全局配置

列出系统配置(List System Configuration)

We can list System Configuration which is user wide configuration with the --list and --global options like below.

我们可以使用--list--global选项列出系统范围的系统配置,如下所示。

List System Configuration
List System Configuration
列出系统配置

设置本地配置(Set Local Configuration)

As stated previously there are 3 level configuration files which have different preferences. While setting some configuration we can specify the configuration level. In order to set Local Configuration which is only used in the current project, we will use --local option like below. In this example, we will set an email address to [email protected].

如前所述,有3个级别的配置文件具有不同的首选项。 在设置一些配置时,我们可以指定配置级别。 为了设置仅在当前项目中使用的本地配置,我们将使用--local选项,如下所示。 在此示例中,我们将电子邮件地址设置为[email protected]

$ git config --local user.email "[email protected]"

设置全局配置 (Set Global Configuration)

We can also set a given configuration in the global level with the  --global option like below. In this example, we will set the email address of the user. By default is there is no explicit level specification the global level will be set.

我们还可以使用--global选项在全局级别设置给定配置,如下所示。 在此示例中,我们将设置用户的电子邮件地址。 默认情况下,没有显式级别规范将设置全局级别。

$ git config --global user.email "[email protected]"

OR

要么

$ git config  user.email "[email protected]"

设置系统配置 (Set System Configuration)

We can also set a given configuration in the system level with the  --system option like below. In this example, we will set the email address of the user.

我们还可以使用--system选项在系统级别设置给定配置,如下所示。 在此示例中,我们将设置用户的电子邮件地址。

$ git config --system user.email "[email protected]"

设定文字编辑器 (Set Text Editor)

While working from the command line or GUI we need to use some text editor in order to edit project files like source code, configuration, documentation, etc. By default, the system default text editor is used with the different git commands to edit source code, configuration, and documentation, etc. We can specify and set the text editor to be used with the Git commands with the core.editor option by adding the editor name or path like below. In this example, we will set the editor like vim.

从命令行或GUI工作时,我们需要使用一些文本编辑器来编辑项目文件,例如源代码,配置,文档等。默认情况下,系统默认的文本编辑器与不同的git命令一起使用来编辑源代码,配置和文档等。我们可以通过添加如下所示的编辑器名称或路径,来指定和设置要与具有core.editor选项的Git命令一起使用的文本编辑器。 在此示例中,我们将编辑器设置为vim。

$ git config core.editor "vim"

Alternatively, we can use the following git config commands to set different popular text editors.

另外,我们可以使用以下git config命令来设置不同的流行文本编辑器。

#Atom Editor
$ git config core.editor "atom"
#Emacs Editor
$ git config core.editor "emacs"
#Nano Editor
$ git config core.editor "nano"
#Vi Editor
$ git config core.editor "vi"
#Sublime On MacOS Editor
$ git config core.editor "subl -n -w "
#Sublime On Windows 32 Bit 
$ git config core.editor "'c:/program files (x86)/sublime text 3/sublimetext.exe' -w"

#Sublime On Windows 64 Bit 
$ git config core.editor "'c:/program files/sublime text 3/sublimetext.exe' -w"

排除文件和扩展名 (Exclude Files and Extensions)

While using Git files under the project will be versioned and saved into the repository. As there is a lot of different type in a project some files may be unnecessary to save or a version like backup, temporary, intermediate files, images, static files, swap files, etc. We can omit them by excluding with their name or extensions.  We will use core.excludefile attribute of the git configuration in order to specify the file names or extensions.  In this example, we will specify the ignore file name which is .gitignore.

在使用Git时,项目下的文件将被版本化并保存到存储库中。 由于项目中存在许多不同类型,因此可能不需要保存某些文件或某些版本,例如备份,临时,中间文件,图像,静态文件,交换文件等。我们可以通过排除其名称或扩展名来省略它们。 我们将使用git配置的core.excludefile属性来指定文件名或扩展名。 在此示例中,我们将指定忽略文件名为.gitignore

$ git config core.excludesfile ".gitignore"
Exclude Files and Extensions
Exclude Files and Extensions
排除文件和扩展名

设置或更改用户名(Set or Change User Name)

While developing applications with git every developer has his own name and email address. We can specify our name which will make it easier to track changes. The developer’s name will be shown the commits, merges, and changes. We can specify the user name with the user.name attribute. In this example, we will set the name as İsmail Baydan.

在使用git开发应用程序时,每个开发人员都有自己的姓名和电子邮件地址。 我们可以指定我们的名称,这将使跟踪更改更加容易。 开发人员的姓名将显示提交,合并和更改。 我们可以使用user.name属性指定用户名。 在此示例中,我们将名称设置为İsmail Baydan

$ git config user.name "İsmail Baydan"

AND print with the following command

使用以下命令打印

$ git config user.name
Set or Change User Name
Set or Change User Name
设置或更改用户名

设置或更改电子邮件地址(Set or Change Email Address)

Every developer generally has some email address which can be used for communication. We will use user.email attribute in order to set an email address for the current user. In this example, we will set [email protected] as an email address.

每个开发人员通常都有一些可用于通信的电子邮件地址。 我们将使用user.email属性来设置当前用户的电子邮件地址。 在此示例中,我们将[email protected]设置为电子邮件地址。

$ git config user.email "[email protected]"

AND we can use the following command in order to print current email address.

并且我们可以使用以下命令来打印当前的电子邮件地址。

$ git config user.email
Set or Change Email Address
Set or Change Email Address
设置或更改电子邮件地址

别名(Aliases)

While using git there are a lot of different simple and complex commands. Some of them are very long to remember and trivial to write. An alias can be used to create an alias for a command which generally shortens the command usage. For example commit command can be shortened as ci as an alias. Git aliases are configured with the git config command and stored in the git configuration file.

使用git时,有许多不同的简单和复杂命令。 其中一些记起来很长,写起来很琐碎。 别名可用于为命令创建别名,这通常会缩短命令的使用。 例如, commit命令可以缩写为ci作为别名。 Git别名使用git config命令配置,并存储在git配置文件中。

创建别名 (Create Alias)

We can create an alias by using alias keyword like below where we will add the alias to the end of alias keyword and then provide the real command. In this example, we will create an alias named ci which will run commit command.

我们可以通过使用如下alias关键字来创建别名,我们将别名添加到alias关键字的末尾,然后提供真实的命令。 在此示例中,我们将创建一个名为ci的别名,该别名将运行commit命令。

$ git config alias.ci commit

We will test ci alias in the following example.

在下面的示例中,我们将测试ci别名。

$ git ci
Run Alias
Run Alias
运行别名

AND we can also use existing aliases in other aliases. In this example, we will use ci alias in amend alias.

并且我们还可以在其他别名中使用现有的别名。 在此示例中,我们将在amend别名中使用ci别名。

$ git config alias.amend ci --amend

在终端中启用颜色 (Enable Colors In Terminal)

Git can be used from the command line or terminal where the output can be colored. By default the git output is colorful. With colors, the output can be interpreted with its colors. We can disable and enable color with the color.ui attribute with the false and true values. The following command will disable terminal colors.

可以从命令行或可以在其中对输出进行着色的终端上使用Git。 默认情况下,git输出是彩色的。 使用颜色时,可以用其颜色解释输出。 我们可以使用带有falsetrue值的color.ui属性禁用和启用颜色。 以下命令将禁用端子颜色。

$ git config color.ui "false"

AND we can enable colors like below.

并且我们可以启用以下颜色。

$ git config color.ui "true"

设置HTTP / HTTPS代理 (Set HTTP/HTTPS Proxy)

While using git in enterprise environments we may need to use an HTTP proxy to access the internet or another network. We can specify an HTTP proxy with the http.proxy attribute. We can also specify an HTTPS proxy with the http.proxy attribute.

在企业环境中使用git时,我们可能需要使用HTTP代理访问Internet或其他网络。 我们可以使用http.proxy属性指定一个HTTP代理。 我们还可以使用http.proxy属性指定一个HTTPS代理。

$ git config http.proxy "http://192.168.1.1"

AND for HTTPS proxy

AND(用于HTTPS代理)

$ git config https.proxy "http://192.168.1.1"

取消设置HTTP / HTTPS代理 (Unset HTTP/HTTPS Proxy)

We can also unset to remove already created a proxy with the --unset option and providing the attributes http.proxy and https.proxy like below.

我们还可以取消设置以使用--unset选项删除已创建的代理,并提供如下所示的属性http.proxyhttps.proxy

$ git config --unset http.proxy

$ git config --unset https.proxy

设置差异/合并工具 (Set Diff/Merge Tool)

While developing applications in order to diff and merge different versions of the code diff/merge tools are used. Git uses the default internal diff tool. But we can change and set the diff tool with the diff.external attribute like below. In this example, we will set the diff tool as diff command.

在开发应用程序以差异化和合并不同版本的代码时,使用差异化/合并工具。 Git使用默认的内部差异工具。 但是我们可以使用diff.external属性更改和设置diff工具,如下所示。 在此示例中,我们将diff工具设置为diff命令。

$ git config diff.tool "diff"

设置Windows自动行尾 (Set Windows Automatic End Of Line)

Windows and Linux operating systems use the different end of line characters for the plain text files. This may create cross-platform problems. As git can be used both in Windows and Linux operation systems it should be set properly. We can enable the automatic end of line detection with the core.autocrlf attribute like below. We will set true value to this attribute.

Windows和Linux操作系统对纯文本文件使用不同的行尾字符。 这可能会产生跨平台的问题。 由于git可以在Windows和Linux操作系统中使用,因此应正确设置。 我们可以使用core.autocrlf属性启用自动行尾检测,如下所示。 我们将为此属性设置true值。

$ git config core.autocrlf true

取消配置 (Unset A Configuration)

Git configuration can be set by using related attributes and by using the --unset option. In this example, we will unset the user.name attribute which will be emptied.

可以使用相关属性或使用--unset选项来设置Git配置。 在此示例中,我们将取消设置将清空的user.name属性。

$ git config user.name --unset

翻译自: https://www.poftut.com/git-config-command-tutorial-with-username-password-email-alias-examples/

git命令 带用户名密码

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值