Git –环境设置和基本配置

Installing git is easy with operating system provided packages like apt or dnf. We can track here Fedora way with dnf but it is very similar for other operating systems like CentOS, Debian, Ubuntu etc.

使用操作系统提供的软件包,如apt或dnf,安装git很容易。 我们可以在这里用dnf跟踪Fedora的方式,但是对于其他操作系统(例如CentOS,Debian,Ubuntu等)则非常相似。

$ dnf install git -y                                                                                                                  
Failed to set locale, defaulting to C                                                                                                 
Last metadata expiration check: 1:28:52 ago on Thu Oct  6 08:01:17 2016.                                                              
Dependencies resolved.

首次配置 (First-Time Configuration)

After installing git making some configuration will make usage of the git more easy. System wide configuration is held in /etc/gitconfig .

安装git后,进行一些配置将使git的使用更加容易。 系统范围的配置保存在/etc/gitconfig

But more practical configuration can be done in the users home directory. .gitconfig file stores user wide configuration and this configuration is used by all projects if project wide configuration is not exists.

但是可以在用户的​​主目录中完成更实际的配置。 .gitconfig文件存储用户范围的配置,如果不存在项目范围的配置,则所有项目都将使用此配置。

$ cat .gitconfig                                                                                                                      
[user]                                                                                                                                
        name = John Doe                                                                                                               
        email = [email protected]

And project specific configuration is held in the .git/config file.

项目特定的配置保存在.git/config文件中。

用户配置 (User Configuration)

As there will be a lot of commit in big repositories user tracking is important. We can set our name and email for the project but setting them globally will make it more practical because we are busy developers and programming a lot of different projects 😉

由于大型存储库中会有大量提交,因此用户跟踪非常重要。 我们可以为该项目设置名称和电子邮件地址,但是在全局范围内进行设置将使其更加实用,因为我们忙于开发人员并且正在对许多不同的项目进行编程😉

$ git config --global user.name "John Doe"         
$ git config --global user.email "[email protected]" 
$ git config -l 
user.name=John Doe 
[email protected] 
core.repositoryformatversion=0 
core.filemode=true 
core.bare=false 
core.logallrefupdates=true

We set our user name with config command for the –global and providing username and email values with user.name and user.email . After setting user info we can check with config -l command.

我们使用config命令为–global设置用户名,并使用user.name和user.email提供用户名和电子邮件值。 设置用户信息后,我们可以使用config -l命令进行检查。

检查配置 (Checking Configuration)

Existing configuration can be listed with config command like below.

现有配置可以使用config命令列出,如下所示。

$ git config --list 
user.name=John Doe 
[email protected]
  • --list is used to list configuration

    --list用于列出配置

LEARN MORE  How To Configure Cisco Routers and Switches Password?
了解更多信息如何配置思科路由器和交换机密码?

获得帮助 (Getting Help)

Before starting to work with git knowing how to get help from git is better.

在开始使用git之前,了解如何从git获得帮助会更好。

$ git 
usage: git [--version] [--help] [-C <path>] [-c name=value] 
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path] 
           [-p | --paginate | --no-pager] [--no-replace-objects] [--bare] 
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>] 
           <command> [<args>] 
 
These are common Git commands used in various situations: 
 
start a working area (see also: git help tutorial) 
   clone      Clone a repository into a new directory 
   init       Create an empty Git repository or reinitialize an existing one 
 
work on the current change (see also: git help everyday) 
   add        Add file contents to the index 
   mv         Move or rename a file, a directory, or a symlink 
   reset      Reset current HEAD to the specified state 
   rm         Remove files from the working tree and from the index 
 
examine the history and state (see also: git help revisions) 
   bisect     Use binary search to find the commit that introduced a bug 
   grep       Print lines matching a pattern 
   log        Show commit logs 
   show       Show various types of objects 
   status     Show the working tree status 
 
grow, mark and tweak your common history 
   branch     List, create, or delete branches 
   checkout   Switch branches or restore working tree files 
   commit     Record changes to the repository 
   diff       Show changes between commits, commit and working tree, etc 
   merge      Join two or more development histories together 
   rebase     Forward-port local commits to the updated upstream head 
   tag        Create, list, delete or verify a tag object signed with GPG 
 
collaborate (see also: git help workflows) 
   fetch      Download objects and refs from another repository 
   pull       Fetch from and integrate with another repository or a local branch 
   push       Update remote refs along with associated objects 
 
'git help -a' and 'git help -g' list available subcommands and some 
concept guides. See 'git help <command>' or 'git help <concept>' 
to read about a specific subcommand or concept.

As we see that git has a lot of commands for different purposes but we will use only some of them in this tutorial. If we need to remember some commands we can use this help.

正如我们看到的,git有很多用于不同目的的命令,但是在本教程中我们只会使用其中一些命令。 如果我们需要记住一些命令,可以使用此帮助。

LEARN MORE  Windows User Management With Net User Like Creating, Deleting, Setting Password
了解更多使用Net用户的Windows用户管理,例如创建,删除,设置密码

初始化git仓库(Initialize git Repository)

Repository is the location where directory and related files reside. If we list files in the initialized path we can see that a hidden directory named .git is created. It is the core where magic happens.

存储库是目录和相关文件所在的位置。 如果我们在初始化路径中列出文件,则可以看到已创建名为.git的隐藏目录。 这是魔术发生的核心。

$ ls -al 
total 12 
drwxr-xr-x 3 root root 4096 Oct  6 09:30 . 
drwxr-xr-x 3 root root 4096 Oct  6 09:30 .. 
drwxr-xr-x 7 root root 4096 Oct  6 09:30 .git
 

翻译自: https://www.poftut.com/git-environment-setup-basic-configuration/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值