最好的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 directoryGit目录
  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)

  • Ubuntu: sudo apt-get install git

    Ubuntu: sudo apt-get install git

  • Windows: Download

    Windows: 下载

  • Mac: Download

    Mac: 下载

配置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教程

最好的git教程_最好的Git教程相关推荐

  1. 克隆git文件_如何在Git中克隆,修改,添加和删除文件

    克隆git文件 在本系列有关Git入门的第一篇文章中 ,我们创建了一个简单的Git存储库,并通过将其连接到计算机将文件添加到其中. 在本文中,我们将学习有关Git的其他一些知识,即如何在Git存储库中 ...

  2. python大神教程_大神python教程415集全套,拿走不谢

    大神的教程 由北京尚学堂高淇老师亲自录制,2019Python自学教程全新升级为<Python+数据分析+机器学习>能力逐级提升,打造技能更全面的全栈工程师. Python作为一种编程语言 ...

  3. 计算机系统精品教程,_《计算机操作系统教程》课程教学课件(精品) 设备管理(88P).pdf...

    _<计算机操作系统教程>课程教学课件(精品) 设备管理(88P).pdf 第8章 设备管理 §8.1 引言 §8.2 数据传送控制方式 §8.3 中断技术 §8.4 缓冲技术 §8.5 设 ...

  4. Word教程_编程入门自学教程_菜鸟教程-免费教程分享

    教程简介 Word 2010入门教程 - 从简单的步骤入门Microsoft Office 2010,从基本到高级概念,包括探索窗口,后台视图,输入文本,移动,打开,关闭文档,上下文帮助,插入,选择, ...

  5. Apache POI(Word)教程_编程入门自学教程_菜鸟教程-免费教程分享

    教程简介 IT宝库整理的Apache POI Word入门教程 - 从基本到高级概念的简单简单步骤学习Apache POI Word,其中包括概述,Apache POI安装,核心类,文档,段落,边框, ...

  6. EJB教程_编程入门自学教程_菜鸟教程-免费教程分享

    教程简介 EJB入门教程 - 从简单的步骤了解EJB 3.0和3.1(Enterprise Java Bean)框架,从基本概念到高级概念,包括概述,环境设置,应用服务器,容器,企业Bean,注释,会 ...

  7. 高级Excel功能教程_编程入门自学教程_菜鸟教程-免费教程分享

    教程简介 Excel是办公室自动化中非常重要的一款软件,Excel函数则是Excel中的内置函数.Excel函数共包含11类,分别是数据库函数.日期与时间函数.工程函数.财务函数.信息函数.逻辑函数. ...

  8. weakauras教程_简单的WeakAuras2教程 基础功能设置指南

    玩家分享简单的WeakAuras2插件的基本攻略设置教程,WeakAuras2作为当今的神级插件已经受到了越来越多玩家的使用,WeakAuras2插件除了可以设置简单的技能监视,能量.蓝量的监控以外还 ...

  9. javplayer 使用教程_意大利单簧管初级教程报名步骤

    意大利单簧管初级教程报名步骤,在课程的设置方面,北京慧禾国际艺术教育更注重于音乐类专业词汇的培训,加强学生生活口语的实际运用,为学生出国留学打下坚实基础. 意大利单簧管初级教程报名步骤, 在笔者使用过 ...

最新文章

  1. java servlet 多线程_Servlet的多线程和线程安全
  2. 饿了么交付中心语言栈转型总结
  3. 超有趣的几个Linux小命令
  4. c#设计模式-工厂方法
  5. 高斯判别分析(GDA)和朴素贝叶斯(NB)
  6. java 泛型嵌套泛型_Java泛型简介–第6部分
  7. 多路复用与设置阻塞、非阻塞模式
  8. 知云文献翻译打不开_比有道更好用的英文文献阅读翻译神器免费啦
  9. 小白设计模式:访问者模式
  10. Linux stat命令和AIX istat命令 (查看文件修改时间)
  11. 深度学习自学(三十六):有效提升图像分类噪声鲁棒性的小波卷积网络
  12. backupexec linux oracle,自动恢复 - 详解通过Backup Exec来实施Oracle灾难恢复_数据库技术_Linux公社-Linux系统门户网站...
  13. MATLAB狼群算法求解车间生产调度问题代码实例(含甘特图)
  14. 解决LDAP客户端统一认证DirectoryEntry出现 Ox80005000的问题
  15. Racket 8.3下载安装(Win10)
  16. 二维码生成及批量生成并打包
  17. 如何在Mac OS X上创建一个Service服务进程
  18. 全球与中国手持式凿岩机市场供需情况分析及十四五趋势预测报告2022-2027年版
  19. 在 VS Code 中开始使用 Python
  20. 《HikariCP数据库连接池实战》学习笔记(二):获取连接原理

热门文章

  1. 【AI视野·今日CV 计算机视觉论文速览 第183期】28 Apr 2020
  2. 二叉树建立及中序遍历C++语言实现
  3. static静态关键词 1214
  4. 学生云课堂 0917
  5. Linux驱动技术(六) _内核中断
  6. LB Cluster 之一:集群及LVS基础理论详解
  7. nagios流量监控报警
  8. jdk1.5-1.7新特性详细介绍
  9. Linux模拟超级终端minicom(二)
  10. vue性能优化-------vendor优化详细用法(瘦身),减小体积,引入cdn