Git_Intro

news/2024/9/22 9:54:51/文章来源:https://www.cnblogs.com/VastEpiphany/p/18392424

目录
  • 1. 实验内容及目的 Contents & Objectives for Lab
  • 2. Git 的简要介绍 Brief Introduction for Git
  • 3. Git的安装 Installation for Git
  • 4. Git的一些基本软件命令操作介绍 Basic Operation Commands for Git
    • 4.1 克隆已有仓库 Clone Existing Repository
    • 4.2 打开现有项目 Open Existing Projects
      • 4.2.1 **进入项目目录 ** Entering the Project Directory
      • 4.2.2 初始化Git仓库 Initializing a Git Repository
      • 4.2.3 添加文件到版本控制 Adding Files to Version Control
      • 4.2.4 **提交初次版本 ** Committing the Initial Version
      • 4.2.5 **连接远程仓库 ** Connecting to a Remote Repository
  • 5. 操作中的问题与解决 Problems & Solutions
  • 6. 实验总结思考点
      • 6.1 Git的实用性
      • 6.2 Git在项目中的作用
      • 6.3 Git学习和实践中的挑战
      • 6.4 总结与展望
  • 7.学习参考资料 Reference Materials for Learning
      • 7.1 官方文档 Official Documentation
      • 7.2 视频课程 Video Courses

1. 实验内容及目的 Contents & Objectives for Lab

a. 了解Git软件的作用,以及其在多人项目管理中所起到的重要作用

b. 学会并掌握Git软件的安装以及配置工作

c. 掌握一些基本的Git命令的操作,例如如何从如GitHub这类的网站上拉取项目,以及如何自己通过Git来创建一个多人管理项目并更新

a. Understand the role of Git software and its importance in managing collaborative projects.

b. Learn and master the installation and configuration of Git software.

c. Master some basic Git commands, such as how to pull projects from websites like GitHub and how to create and update a collaborative project using Git.


2. Git 的简要介绍 Brief Introduction for Git

Git是一个源码开放的分布式版本控制软件系统,用户使用它能够更加有效且高速地进行不同大小的版本项目管理。其最初由最初由林纳斯·托瓦兹创作,于2005年以GPL许可协议发布。

在主要功能上,git是用于Linux内核开发的版本控制工具。与CVS、Subversion一类的集中式版本控制工具不同,它采用了分布式版本库的作法,不需要服务器端软件,就可以运作版本控制,使得源代码的发布和交流极其方便。git的速度很快,这对于诸如Linux内核这样的大项目来说自然很重要。git最为出色的是它的合并追踪(merge tracing)能力。

实际上Linux内核开发团队决定开始开发和使用git来作为内核开发的版本控制系统的时候,世界上开源社群的反对声音不少,最大的理由是git太艰涩难懂,从git的内部工作机制来说,的确是这样。但是随着开发的深入,git的正常使用都由一些友善的命令来执行,使git变得非常好用。现在,越来越多的著名项目采用git来管理项目开发,例如:wine、U-boot等。

作为开源自由原教旨主义项目,git没有对版本库的浏览和修改做任何的权限限制,通过其他工具也可以达到有限的权限控制,比如:gitosis、CodeBeamer MR。原本git的使用范围只适用于Linux/Unix平台,但在Windows平台下的使用也日渐成熟,这主要归功于Cygwin、msysgit环境,以及TortoiseGit这样易用的GUI工具。git的源代码中也已经加入了对Cygwin与MinGW编译环境的支持且逐渐完善,为Windows用户带来福音。

同样地,在实现原理上,git和其他版本控制系统(如CVS)有不小的差别,git本身关心文件的整体性是否有改变,但多数的版本控制系统如CVS或Subversion系统则在乎文件内容的差异。git拒绝保持每个文件的版本修订关系。因此查看一个文件的历史需要遍历各个history快照;git隐式处理文件更名,即同名文件默认为其前身,如果没有同名文件则在前一个版本中搜索具有类似内容的文件。

git更像一个文件系统,直接在本地上获取资料,不必连线到主机端获取资料。 每个开发者都可有全部开发历史的本地副本,changes从这种本地repository复制给其他开发者。这些changes作为新增的开发分支被导入,可以与本地开发分支合并。

Git is an open-source distributed version control software system that allows users to manage projects of various sizes more efficiently and quickly. It was originally created by Linus Torvalds and released in 2005 under the GPL license.

In terms of functionality, Git is a version control tool used for Linux kernel development. Unlike centralized version control tools such as CVS and Subversion, Git uses a distributed repository approach, which means it can operate without server-side software, making source code distribution and collaboration extremely convenient. Git is also very fast, which is important for large projects like the Linux kernel. One of Git's most outstanding features is its merge tracking capability.

When the Linux kernel development team decided to start developing and using Git as the version control system for kernel development, there was a lot of opposition from the open-source community, with the main reason being that Git was too complex and difficult to understand. From Git's internal working mechanism, this criticism was indeed valid. However, as development progressed, Git's usage was facilitated by friendly commands, making it much more user-friendly. Nowadays, many well-known projects, such as Wine and U-Boot, use Git to manage their development.

As a project rooted in open-source freedom principles, Git does not impose any permission restrictions on repository browsing and modifications. However, limited permission control can be achieved through other tools such as gitosis and CodeBeamer MR. Originally, Git was only used on Linux/Unix platforms, but its usage on Windows has also become increasingly mature, thanks to environments like Cygwin, msysgit, and user-friendly GUI tools like TortoiseGit. Git's source code now includes support for Cygwin and MinGW compilation environments, which have gradually improved, bringing benefits to Windows users.

Similarly, in terms of implementation, Git differs significantly from other version control systems such as CVS. Git focuses on whether the integrity of a file has changed, while most version control systems, like CVS or Subversion, are concerned with the differences in file content. Git does not maintain a version history for each file. Therefore, viewing the history of a file requires traversing each history snapshot; Git implicitly handles file renaming by assuming that a file with the same name is its predecessor. If there is no file with the same name, it searches for files with similar content in the previous version.

Git functions more like a file system, retrieving data locally without needing to connect to a remote server. Each developer can have a complete local copy of the development history, and changes can be copied from this local repository to other developers. These changes are imported as new development branches, which can then be merged with local development branches.

图1: Git标志

3. Git的安装 Installation for Git

注意:由于本人的电脑已经安装有Git,故为演示操作,本安装操作均在 WIndows 8 虚拟机系统下进行

首先,我们登录Git的官方网站,并且通过其 下载页面以下载对应系统版本的Git软件。在这里,我们以Windows系统为例。

Note: Since Git is already installed on my computer, for demonstration purposes, this installation will be performed on a Windows 8 virtual machine.

First, we log in to Git's official website and download the appropriate version of Git for your system through its download page. Here, we will take the Windows system as an example.

图2: Git下载界面

点击Windows版本下载,并且以管理员身份运行对应的 exe 文件,开始会展示对应的Info信息,点击Next,来到选择对应安装组件的界面(如下图所示),在这里我们可以选择如是否添加图标、是否在右键添加Git操作选项以及是否与对应文件相关联、检查更新等操作。我们按照自己的需求勾选对应选项,点击Next进入下一步。

Click to download the Windows version, and run the corresponding exe file as an administrator. The installation will begin by displaying the relevant Info information. Click "Next" to proceed to the component selection screen (as shown in the image below). Here, you can choose options such as adding icons, adding Git options to the right-click context menu, associating Git with corresponding files, and checking for updates. Select the options according to your needs, then click "Next" to proceed to the next step.

图3: Git Select Components组件安装选择界面

接下来需要我们注意的便是对于默认Editor的选择问题,Vim编辑器由于历史遗留以及不够直观等问题,已经不再推荐使用,这里使用Nano Editor进行安装:

Next, we need to pay attention to the selection of the default editor. Due to historical issues and lack of intuitiveness, the Vim editor is no longer recommended. Here, we will select Nano Editor for installation:

图4: Git Default editor默认编辑器选择界面

接下来的操作可以按照默认进行即可,一路点击继续,我们看到绿色的安装进度条以及最终的安装成功提示界面后,便证明我们已经成功在我们的系统中安装好了Git版本控制软件。

The subsequent operations can be performed with the default settings. Simply continue clicking "Next." Once you see the green installation progress bar and the final installation success screen, it confirms that Git version control software has been successfully installed on your system.

图5: Git 安装以及完成界面

4. Git的一些基本软件命令操作介绍 Basic Operation Commands for Git

对于Git这个软件,我们可以主要用来进行仓库项目的克隆、推送、创建以及打开对应的本地项目。接下来我们就以简单的几个例子来介绍我们的操作流程。

With Git, we can primarily use it to clone, push, create repositories, and open corresponding local projects. Next, we will introduce our workflow through a few simple examples.

4.1 克隆已有仓库 Clone Existing Repository

当我们在GitHub上看到我们感兴趣的开源项目并且想将其复制到本地来进行下一步的研究时,我们通常会用到Git软件的Clone命令来将项目复制到本地,一般而言,Clone命令的主要组织形式大致如下:

When we see an open source project on GitHub that we are interested in and want to copy it locally for the next step in our research, we usually use the Git software's Clone command to copy the project locally, and in general, the main organization of the Clone command is roughly as follows:

git clone GIT_URL YOUR_DESTINATION

其中,GIT_URL为网站Repository中所给的连接地址,而YOUR_DESTINATION则为项目所克隆到的本地目标位置。以我在GitHub上的一个项目为例,在网站上,我们可以看到对应的克隆地址,我想将其拷贝到本地的桌面中,因此打开Git的CMD命令行窗口,输入对应的命令,得到下图7所示的结果,即代表项目已经成功克隆到对应的路径下:

Where GIT_URL is the connection address given in the website Repository, and YOUR_DESTINATION is the local target location that the project is cloned to. Take one of my projects on GitHub as an example, on the website, we can see the corresponding clone address, I want to copy it to the local desktop, so open the CMD command line window of Git, enter the corresponding commands, and get the results shown in Figure 7 below, that is, it means that the project has been successfully cloned to the corresponding path:

图6: Repository仓库Git的克隆地址寻找

图7: 成功克隆

4.2 打开现有项目 Open Existing Projects

打开本地的现有项目并且将其加入版本控制主要分为以下几个步骤:首先是进入项目目录,而后我们需要初始化Git仓库,而后再将文件添加到版本控制。

There are several steps to open an existing local project and add it to version control: first, you need to enter the project directory, then you need to initialize the Git repository, and then you need to add the files to version control.

4.2.1 **进入项目目录 ** Entering the Project Directory

打开终端或命令提示符,并导航到你想要使用Git进行版本控制的本地项目目录。例如:

cd "C:\Users\Jerry Brown\Desktop\Your_Project"

如果目录路径中有空格,请记得使用双引号包裹路径。

4.2.2 初始化Git仓库 Initializing a Git Repository

进入项目目录后,运行以下命令来初始化一个新的Git仓库:

Once in the project directory, run the following command to initialize a new Git repository:

git init

这个命令会在当前目录中创建一个隐藏的 .git 文件夹,Git会在这个文件夹中保存与版本控制相关的信息。

This command will create a hidden .git folder in the current directory, where Git will store information related to version control.

4.2.3 添加文件到版本控制 Adding Files to Version Control

运行以下命令,将当前项目中的所有文件添加到Git的暂存区:

Run the following command to add all files in the current project to Git’s staging area:

git add .

这里的 . 表示将当前目录中的所有文件和文件夹添加到暂存区。你也可以指定某个文件或文件夹来添加。

The . indicates that all files and folders in the current directory should be added to the staging area. You can also specify individual files or folders to add.

4.2.4 **提交初次版本 ** Committing the Initial Version

添加文件到暂存区后,可以使用以下命令提交第一个版本:

After adding files to the staging area, you can use the following command to commit the first version:

git commit -m "Initial commit"

-m "Initial commit" 用来添加提交时的备注信息,这条信息描述了这次提交的内容。

​ The -m "Initial commit" option adds a message to the commit, describing the content of this commit.

4.2.5 **连接远程仓库 ** Connecting to a Remote Repository

如果我们有远程仓库(例如在GitHub或GitLab上),可以使用以下命令将本地仓库与远程仓库关联:

If you have a remote repository (e.g., on GitHub or GitLab), you can use the following command to link the local repository to the remote one:

git remote add origin https://github.com/YourUsername/YourRepository.git

然后推送代码到远程仓库:

Then push the code to the remote repository:

git push -u origin master

这样,我们就可以在本地项目中使用Git进行版本控制,并且可以选择将其推送到远程仓库中。

In this way, you can use Git for version control in your local project and optionally push it to a remote repository.


5. 操作中的问题与解决 Problems & Solutions

在Git clone中,我们可能会遇到如下connection error问题:

In Git clone, we might face the connection error problem:

图8: 连接错误问题 Connection Error Problem

在确保网络连接正常之后,我们可以通过分别输入以下命令行解决:

First to make sure that the Internet connection is working, we can solve this problem by inputing these two lines of codes respectively:

git config --global http.proxy socks5 127.0.0.1:7890
git config --global https.proxy socks5 127.0.0.1:7890

6. 实验总结思考点

在总结Git的安装与实践操作时,可以从以下几个方面进行思考和总结:

6.1 Git的实用性

  • 版本控制的核心工具:Git作为一个分布式版本控制系统,能够有效管理项目中的代码版本。通过Git,开发者可以轻松地追踪代码的历史变化,快速回滚到早期版本,并在团队协作中减少冲突。
    Core Tool for Version Control: As a distributed version control system, Git effectively manages code versions in a project. With Git, developers can easily track changes in code history, quickly revert to earlier versions, and reduce conflicts in team collaboration.

  • 提高开发效率:在多人协作开发中,Git提供了分支功能,使得开发者可以在独立的分支上进行开发,而不会影响主线代码。这种并行开发的方式显著提升了开发效率,并减少了开发过程中出错的风险。
    Improving Development Efficiency: In collaborative development, Git provides branching functionality, allowing developers to work on separate branches without affecting the mainline code. This parallel development approach significantly enhances development efficiency and reduces the risk of errors during development.

6.2 Git在项目中的作用

  • 分布式特点:Git的分布式架构意味着每个开发者都拥有整个项目的完整历史记录,这不仅提高了项目的安全性(防止数据丢失),还增强了开发者的灵活性,即使没有网络连接也能进行操作。
    Distributed Nature: Git's distributed architecture means that every developer has a complete history of the entire project, which not only increases project security (preventing data loss) but also enhances developer flexibility, allowing operations even without network connectivity.

  • 强大的分支管理:Git的分支机制非常强大和灵活,允许开发者创建、合并和删除分支。通过分支,开发者可以轻松实现不同功能的开发、测试、上线,并在必要时进行分支合并,从而确保代码的稳定性。
    Powerful Branch Management: Git's branching mechanism is very powerful and flexible, allowing developers to create, merge, and delete branches. With branching, developers can easily develop, test, and deploy different features, and merge branches when necessary to ensure code stability.

  • 简化协作流程:通过Git,团队可以通过Pull Request或Merge Request等方式进行代码审查,保证代码质量。此外,Git的分布式特性也方便团队在不同地点进行协作开发,避免了中央服务器的单点故障问题。
    Simplified Collaboration: With Git, teams can conduct code reviews through Pull Requests or Merge Requests to ensure code quality. Additionally, Git's distributed nature facilitates collaborative development from different locations, avoiding the single point of failure issue of a central server.

6.3 Git学习和实践中的挑战

  • 命令行工具的学习:虽然Git的命令行工具功能强大,但对于初学者来说,命令的复杂性可能会带来一定的学习曲线。需要通过不断实践和查阅文档,逐步掌握常用命令的使用。
    Learning Command-Line Tools: Although Git's command-line tools are powerful, their complexity can present a learning curve for beginners. Continuous practice and consultation of documentation are required to gradually master the use of common commands.

  • 版本冲突的处理:在多人协作时,版本冲突不可避免,如何有效处理冲突、合理规划分支策略也是实践中需要重点掌握的内容。
    Handling Version Conflicts: In collaborative environments, version conflicts are inevitable. Effectively handling conflicts and planning branch strategies are key aspects that need to be mastered in practice.

6.4 总结与展望

  • 实用性和普及性:Git作为目前最流行的版本控制工具,其应用范围已经超出了软件开发领域,广泛用于文档管理、数据分析、研究项目等各个领域。掌握Git不仅是开发者的基本技能,也对提升项目管理和团队协作能力有显著帮助。
    Practicality and Popularity: As the most popular version control tool today, Git's application extends beyond software development to document management, data analysis, research projects, and more. Mastering Git is not only a fundamental skill for developers but also significantly enhances project management and team collaboration abilities.

  • 未来应用的思考:随着DevOps、CI/CD等现代开发流程的普及,Git在自动化部署、持续集成中的作用越来越突出。未来在使用Git时,可以更深入地结合这些工具,提高项目开发和发布的效率。
    Future Applications: With the rise of modern development processes like DevOps and CI/CD, Git's role in automated deployment and continuous integration is becoming more prominent. In the future, using Git in conjunction with these tools can further enhance project development and release efficiency.

相信通过对Git的实践操作,不仅加深了我们对其核心概念的理解,同时也为我们今后的项目开发提供了强有力的工具支持。
By practicing Git, we have deepened our understanding of its core concepts and provided strong tool support for our future project development.


7.学习参考资料 Reference Materials for Learning

以下是一些学习Git的参考资料,包括文档、书籍、在线课程和社区资源,适合我们不同水平的学习者以供学习:
Below are some references for learning Git, including documentation, books, online courses, and community resources, suitable for learners at different levels:

7.1 官方文档 Official Documentation

  • Git 官方文档 (英文)
    Git官网提供的文档非常详尽,涵盖了从入门到高级使用的各个方面。适合需要深入理解Git命令和工作原理的学习者。
    Git Official Documentation (English)
    The documentation provided by Git's official website is very detailed, covering all aspects from beginner to advanced usage. It is suitable for learners who need a deep understanding of Git commands and working principles.

  • Pro Git (中文翻译)
    这本书是Git的官方推荐教材,内容全面且易于理解,适合系统性学习Git。
    Pro Git (Chinese Translation)
    This book is an officially recommended textbook by Git. It is comprehensive and easy to understand, making it suitable for systematic learning of Git.

7.2 视频课程 Video Courses

  • Coursera 上的 Version Control with Git
    Coursera的Git课程,由知名大学和机构提供,课程质量较高,并且可以获得认证。
    Version Control with Git on Coursera
    The Git course on Coursera, provided by well-known universities and institutions, offers high-quality content and certification options.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/790954.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

《花100块做个摸鱼小网站! 》第五篇—通过xxl-job定时获取热搜数据

⭐️基础链接导航⭐️ 服务器 → ☁️ 阿里云活动地址 看样例 → 🐟 摸鱼小网站地址 学代码 → 💻 源码库地址一、前言 我们已经成功实现了一个完整的热搜组件,从后端到前端,构建了这个小网站的核心功能。接下来,我们将不断完善其功能,使其更加美观和实用。今天的主题是…

《网络数据安全管理条例(草案)》已审议通过

根据新华社北京8月30日电 国务院总理李强8月30日主持召开国务院常务会议,研究推动保险业高质量发展的若干意见,部署落实大食物观相关工作,审议通过《加快完善海河流域防洪体系实施方案》和《网络数据安全管理条例(草案)》,讨论《中华人民共和国海商法(修订草案)》。会…

Linux系统添加软件快捷方式 (图标)

Linux系统添加软件快捷方式 (图标) 背景 在Linux系统下安装软件,安装软件后,常常缺少软件的快捷方式,不熟悉Linux系统的同学甚至不知道软件安装的位置,就算知道软件安装位置的同学也会因打开点开一大堆文件夹而头疼,因此,在Linux系统性为常用软件添置快捷方式显得尤为重…

工作五年小结 | 面对不确定性快速上升的外部环境,我们该如何寻求突破?

1. 前言工作五年了,来京东马上满一年,前四年在开水团,不禁感叹时间过的真快啊!回想19年从西安交大硕士毕业孤身前往北京开始职业生涯,经历了孤独迷茫到自立坚定,再到23年下定决心携妻还蜀安家,并来到京东开始新的征程,这5年过的很快也很充实。今年也是我的而立之年,感…

像操作tar文件一样操作jar文件,让很多事情变得简单

原创 1024夜谭jar文件即Java归档文件,也称为jar包,是Java应用软件或库,通常聚合了大量的Java类文件、相关的元数据和资源文件。通常由构建工具产生,可以使用IDE、反编译工具或者Java诊断工具如Arthas等查看内容。 如果你对tar命令使用得心应手,那么你将发现jar操作与tar操…

Spearman相关性分析 —— 入门案例

简介 Spearman相关系数,也称为Spearman等级相关系数,是一种非参数的统计度量,用于评估两个变量之间的相关性,即它们是否以某种一致的方式一起变化。与皮尔逊相关系数不同,Spearman相关系数不假设数据是正态分布的,也不要求变量是线性关系。Spearman的检验 在统计学中,p值…

.NET 8.0 前后分离快速开发框架

前言 大家好,推荐一个.NET 8.0 为核心,结合前端 Vue 框架,实现了前后端完全分离的设计理念。它不仅提供了强大的基础功能支持,如权限管理、代码生成器等,还通过采用主流技术和最佳实践,显著降低了开发难度,加快了项目交付速度。 如果你需要一个高效的开发解决方案,本框…

一维卡尺边缘对

一、代码部分* 一维卡尺 边缘对read_image (Image, printer_chip/printer_chip_01)*打开助手操作生成代码* Measure 02: Code generated by Measure 02 * Measure 02: Prepare measurement AmplitudeThreshold := 40 RoiWidthLen2 := 5 set_system (int_zooming, true) * Measu…

mongodb 集合的导入导出

在新版本的mongodb中已经不默认安装这些工具,需要到mongodb网站单独下载 https://www.mongodb.com/try/download/database-tools 下载完成后使用scp D:\mongodb-tools.tgz root@8.143.49.192:/home/mongodb_tools.tgz命令将文件复制到linux服务器用 tar -zxvf demo.tar.gz -C …

nginx 版本升级 转载

Nginx 的版本最开始使用的是 Nginx-1.18.0 , 由于服务升级,需要将 Nginx 的版本升级到 Nginx-1.19.7 ,要求 Nginx 不能中断提供服务。 为了应对上述的需求,提供两种解决方案: 方案1: make upgrade 完成升级方案2: 服务信号 完成升级nginx 版本升级环境说明当前是 CentOS…

如何从 AWS CodeCommit 迁移到极狐GitLab?

本文将分享如何从 AWS CodeCommit 服务无缝迁移到极狐GitLab,并且使用极狐GitLab 的一体化 DevSecOps 平台功能来进行软件研发。2024 年 7 月 25 日,AWS 官方发布了一则重要通知:旗下的代码托管服务 AWS CodeCommit 服务将不再接受新用户的注册,老用户可以继续使用,但是该…