最好的git教程_最好的Git教程

最好的git教程

Git is an open source distributed version control system created in 2005 by Linus Torvalds and others from the Linux development community. Git can work with many types of projects, but it’s most commonly used for software source code.

Git是Linus Torvalds和Linux开发社区的其他人于2005年创建的开源分布式版本控制系统。 Git可以处理许多类型的项目,但是最常用于软件源代码。

Version control is a system that keeps track of changes to a file or group of files over time. When you have a history of these changes, it lets you find specific versions later, compare changes between versions, recover files you may have deleted, or revert files to previous versions.

版本控制是一个跟踪一段时间内对一个文件或一组文件的更改的系统。 拥有这些更改的历史记录后,它可以让您以后查找特定版本,比较版本之间的更改,恢复可能已删除的文件或将文件还原为以前的版本。

A distributed version control system means that different users maintain their own repositories of a project, instead of working from one central repository. Users automatically have full file tracking abilities and the project’s complete version history without needing access to a central server or network.

分布式版本控制系统意味着不同的用户可以维护他们自己的项目存储库,而不是从一个中央存储库进行工作。 用户自动具有完整的文件跟踪能力和项目的完整版本历史记录,而无需访问中央服务器或网络。

When Git is initialized in a project directory, it begins tracking file changes and stores them as “change sets” or “patches.” Users working together on a project submit their change sets which are then included (or rejected) in the project.

在项目目录中初始化Git后,它将开始跟踪文件更改并将其存储为“更改集”或“补丁”。 在项目上共同工作的用户将提交他们的变更集,然后将其包含(或拒绝)到项目中。

freeCodeCamp has a YouTube playlist with lots of practical Git and GitHub tips here.

freeCodeCamp在这里有一个YouTube播放列表,其中包含许多实用的Git和GitHub技巧

其他教程: (Other tutorials:)

  • The Pro Git book, written by Scott Chacon and Ben Straub and published by Apress. The book is displayed in full in the Git documentation.

    Pro Git书,由Scott Chacon和Ben Straub撰写,由Apress出版。 这本书在Git文档中完整显示。

  • For downloads, documentation, and a browser-based tutorial: Git official website

    有关下载,文档和基于浏览器的教程: Git官方网站

  • Most useful commands when you’re in bad GIT situation: Oh s***, git!

    在GIT状况不佳时最有用的命令: 哦s ***,git!

了解Git项目的三个部分 (Understand the Three Sections of a Git Project)

A Git project will have the following three main sections:

Git项目将包含以下三个主要部分:

  1. Git directory

    Git目录
  2. Working directory (or working tree)

    工作目录(或工作树)
  3. Staging area

    暂存区

The Git directory (located in YOUR-PROJECT-PATH/.git/) is where Git stores everything it needs to accurately track the project. This includes metadata and an object database which includes compressed versions of the project files.

Git目录 (位于YOUR-PROJECT-PATH/.git/ )是Git存储准确跟踪项目所需的所有内容的位置。 这包括元数据和一个对象数据库,其中包含项目文件的压缩版本。

The working directory is where a user makes local changes to a project. The working directory pulls the project’s files from the Git directory’s object database and places them on the user’s local machine.

用户在工作目录中对项目进行本地更改。 工作目录从Git目录的对象数据库中提取项目的文件,并将其放置在用户的本地计算机上。

The staging area is a file (also called the “index”, “stage”, or “cache”) that stores information about what will go into your next commit. A commit is when you tell Git to save these staged changes. Git takes a snapshot of the files as they are and permanently stores that snapshot in the Git directory.

暂存区域是一个文件(也称为“索引”,“阶段”或“缓存”),用于存储有关下一次提交内容的信息。 提交是指您告诉Git保存这些阶段的更改。 Git照原样拍摄文件快照,并将该快照永久存储在Git目录中。

With three sections, there are three main states that a file can be in at any given time: committed, modified, or staged. You modify a file any time you make changes to it in your working directory. Next, it’s staged when you move it to the staging area. Finally, it’s committed after a commit.

在三个部分中,文件可以在任何给定时间处于三种主要状态:提交,修改或暂存。 您修改一个文件您在您的工作目录更改它的任何时间。 其次,这是当你将它移动到临时区域上演 。 最后,在提交之后提交。

安装Git (Install Git)

配置Git环境 (Configure the Git Environment)

Git has a git config tool that allows you to customize your Git environment. You can change the way Git looks and functions by setting certain configuration variables. Run these commands from a command line interface on your machine (Terminal in Mac, Command Prompt or Powershell in Windows).

Git有一个git config工具,可让您自定义Git环境。 您可以通过设置某些配置变量来更改Git的外观和功能。 从计算机上的命令行界面(在Mac中为终端,在Windows中为Command Prompt或Powershell)运行这些命令。

There are three levels of where these configuration variables are stored:

这些配置变量的存储级别分为三个级别:

  1. System: located in /etc/gitconfig, applies default settings to every user of the computer. To make changes to this file, use the --system option with the git config command.

    系统:位于/etc/gitconfig ,将默认设置应用于计算机的每个用户。 要对此文件进行更改,请在git config命令中使用--system选项。

  2. User: located in ~/.gitconfig or ~/.config/git/config, applies settings to a single user. To make changes to this file, use the --global option with the git config command.

    用户:位于~/.gitconfig~/.config/git/config ,将设置应用于单个用户。 要对此文件进行更改,请在git config命令中使用--global选项。

  3. Project: located in YOUR-PROJECT-PATH/.git/config, applies settings to the project only. To make changes to this file, use the git config command.

    项目:位于YOUR-PROJECT-PATH/.git/config ,仅将设置应用于项目。 要对此文件进行更改,请使用git config命令。

If there are settings that conflict with each other, the project-level configurations will override the user-level ones, and the user-level configurations will override the system-level ones.

如果存在彼此冲突的设置,则项目级别的配置将覆盖用户级别的配置,而用户级别的配置将覆盖系统级别的配置。

Note for Windows users: Git looks for the user-level configuration file (.gitconfig) in your $HOMEdirectory (C:\Users\$USER). Git also looks for /etc/gitconfig, although it’s relative to the MSys root, which is wherever you decide to install Git on your Windows system when you run the installer. If you are using version 2.x or later of Git for Windows, there is also a system-level config file at C:\Documents and Settings\All Users\Application Data\Git\config on Windows XP, and in C:\ProgramData\Git\config on Windows Vista and newer. This config file can only be changed by git config -f FILE as an admin.

Windows用户注意事项:Git在$HOME目录( C:\Users\$USER )中查找用户级别的配置文件( .gitconfig )。 Git还会查找/etc/gitconfig ,尽管它是相对于MSys根目录的,但在运行安装程序时,无论您决定在Windows系统上安装Git,它都是该根目录。 如果您使用的是Windows 2.x或更高版本的Git,则在Windows XP上的C:\Documents and Settings\All Users\Application Data\Git\config以及C:\ProgramData\Git\config也有一个系统级的配置文件C:\ProgramData\Git\config Windows Vista及更高版本上的C:\ProgramData\Git\config 。 此配置文件只能由git config -f FILE更改为管理员。

添加您的姓名和电子邮件 (Add Your Name and Email)

Git includes the user name and email as part of the information in a commit. You’ll want to set this up under your user-level configuration file with these commands:

Git在提交中将用户名和电子邮件作为信息的一部分。 您需要使用以下命令在用户级配置文件下进行设置:

git config --global user.name "My Name"
git config --global user.email "myemail@example.com"
更改文字编辑器 (Change Your Text Editor)

Git automatically uses your default text editor, but you can change this. Here’s an example to use the Atom editor instead (the --wait option tells the shell to wait for the text editor so you can do your work in it before the program moves on):

Git自动使用您的默认文本编辑器,但是您可以更改它。 这是一个改用Atom编辑器的示例( --wait选项告诉Shell等待文本编辑器,以便您可以在程序继续之前在其中进行工作):

git config --global core.editor "atom --wait"
为Git输出添加颜色 (Add Color to Git Output)

You can configure your shell to add color to Git output with this command:

您可以使用以下命令将外壳配置为向Git输出添加颜色:

git config --global color.ui true

To see all your configuration settings, use the command git config --list.

要查看所有配置设置,请使用命令git config --list

在项目中初始化Git (Initialize Git in a Project)

Once Git is installed and configured on your computer, you need to initialize it in your project to start using its version control powers. In the command line, use the cd command to navigate to the top-level (or root) folder for your project. Next, run the command git init. This installs a Git directory folder with all the files and objects Git needs to track your project.

一旦在计算机上安装并配置了Git,就需要在项目中对其进行初始化,以开始使用其版本控制功能。 在命令行中,使用cd命令导航到项目的顶级(或根)文件夹。 接下来,运行命令git init 。 这将安装一个Git目录文件夹,其中包含Git跟踪项目所需的所有文件和对象。

It’s important that the Git directory is installed in the project root folder. Git can track files in subfolders, but it won’t track files located in a parent folder relative to the Git directory.

将Git目录安装在项目根文件夹中非常重要。 Git可以跟踪子文件夹中的文件,但不会跟踪相对于Git目录的父文件夹中的文件。

在Git中获得帮助 (Get Help in Git)

If you forget how any command works in Git, you can access Git help from the command line several ways:

如果您忘记了任何命令在Git中的工作方式,则可以通过几种方式从命令行访问Git帮助:

git help COMMAND
git COMMAND --help
man git-COMMAND

This displays the manual page for the command in your shell window. To navigate, scroll with the up and down arrow keys or use the following keyboard shortcuts:

这将在您的shell窗口中显示该命令的手册页。 要进行导航,请使用向上和向下箭头键滚动或使用以下键盘快捷键:

  • f or spacebar to page forward

    fspacebar可向前翻页

  • b to page back

    b返回页面

  • q to quit

    q退出

Git和GitHub之间的区别 (Difference between Git and GitHub)

Git and Github are two different things. Git is the version control system, while GitHub is a service for hosting Git repos that helps people collaborate on writing software. However, they are often confounded because of their similar name, because of the fact that GitHub builds on top of Git, and because many websites and articles don’t make the difference between them clear enough.

Git和Github是两回事。 Git版本控制系统 ,而GitHub是托管Git回购的服务,可帮助人们在编写软件方面进行协作。 但是,由于名称相似,GitHub建在Git之上,以及许多网站和文章并没有使它们之间的区别不够明显,所以它们常常会混淆。

吉特 (Git)

Git is the distributed version control system. Git is responsible for keeping track of changes to content – usually source code files.

Git是分布式版本控制系统。 Git负责跟踪内容更改-通常是源代码文件。

For more info, there is a complete article about Git itself.

有关更多信息,请参阅有关Git本身完整文章

的GitHub (GitHub)

GitHub is a service that provides Git repository hosting. That means that they provide a turnkey solution to host Git repositories on their servers. That can be useful to keep a backup of your repository (Git only tracks the changes made to your files over time; the repo still needs to be backed up), and to have a centralized place to keep and share your code with others.

GitHub是一项提供Git存储库托管的服务。 这意味着他们提供了一个交钥匙解决方案,可以在其服务器上托管Git存储库。 这对于保留存储库的备份(Git仅跟踪随着时间的推移对文件所做的更改;回购仍需要备份)很有用,并且在集中的地方可以与他人共享和共享您的代码。

More than just a Git repository hosting service, GitHub is a software forge. That means it also provides an issue tracker, tools for code review, and other tools for collaborating with other people and creating software.

GitHub不仅仅是一个Git仓库托管服务,还是一个软件伪造 。 这意味着它还提供了一个问题跟踪器 ,用于代码审阅的工具以及用于与其他人协作和创建软件的其他工具。

GitHub isn’t the only one to provide this kind of service. One of its major competitors is GitLab. For more on this, look at the section about Git hosting.

GitHub并不是唯一提供这种服务的人。 它的主要竞争对手之一是GitLab 。 有关更多信息,请参阅有关Git托管部分

如何使用SSH与GitHub进行身份验证 (How to authenticate with GitHub using SSH)

Check that there are no rsa files here before continuing, use:

在继续操作之前,请检查此处是否没有rsa文件,请使用:

ls -al ~/.ssh

If there is nothing to list (i.e. : No such file or directory) then use:

如果没有要列出的内容(即: No such file or directory ),请使用:

mkdir $HOME/.ssh

If there’s nothing there then generate a new keygen with:

如果没有任何内容,则使用以下命令生成一个新的密钥源:

ssh-keygen -t rsa -b 4096 -C your@email.com

Now using ls -al ~/.ssh will show our id_rsa.pub file.

现在使用ls -al ~/.ssh将显示我们的id_rsa.pub文件。

Add the SSH key to the SSH agent:

将SSH密钥添加到SSH代理中:

eval "$(ssh-agent -s)" # for mac and Linux from bash
eval `ssh-agent -s`
ssh-agent -s # for Windows

Add RSA key to SHH with:

使用以下命令将RSA密钥添加到SHH:

ssh-add ~/.ssh/id_rsa

Copy your key to clipboard

将密钥复制到剪贴板

clip < ~/.ssh/id_rsa.pub # Windows
cat ~/.ssh/id_rsa.pub # Linux

Go to your GitHub settings page and click the ‘New SSH key’ button paste in your generated key.

转到GitHub 设置页面,然后单击“新建SSH密钥”按钮,将其粘贴到生成的密钥中。

Then authenticate with:

然后通过以下方式进行身份验证:

ssh -T git@github.com

翻译自: https://www.freecodecamp.org/news/best-git-tutorial/

最好的git教程

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值