• 【Linux】题解:Linux环境基础开发工具——Git


    【Linux】题解:Linux环境基础开发工具——Git

    摘要:在实际开发过程中,经常需要对代码进行管理,同样有时需要会遇到小组合作共同开发一个程序,需要代码协助,有时需要对代码进行开源,希望给更多人可以看到,进行共享,这时我们可以使用git,将代码上传到远端仓库,既可以方便管理,又实现了代码的共享等功能。在本文中,将简单介绍关于Linux下对git的使用,由于github在国内较难登录,因此本文通过gitee举例。


    一. 概述

    Linux作为一个操作系统,有着自己开发程序的方式。各位都知道,Linux主要面向的是像程序员这样的群体,因此缺少像VS或者Pycharm等那样的庞大的商用的集成开发工具。不过Linux也是可以做到,像其他IDE那样进行开发,主要的实现方式就是通过指令的形式进行完成。

    Linux环境基础开发工具包括六大板块:

    • 学习yum工具,进行软件安装
    • 掌握vim编辑器使用,学会vim的简单配置
    • 掌握gcc/g++编译器的使用,并了解其过程,原理
    • 掌握简单gdb使用于调试
    • 掌握简单的Makefile编写,了解其运行思想
    • 学习 git 命令行的简单操作, 能够将代码上传到码云上

    在实际开发过程中,经常需要对代码进行管理,同样有时需要会遇到小组合作共同开发一个程序,需要代码协助,有时需要对代码进行开源,希望给更多人可以看到,进行共享,这时我们可以使用git,将代码上传到远端仓库,既可以方便管理,又实现了代码的共享等功能。

    在本文中,将简单介绍关于Linux下对git的使用,由于github在国内较难登录,因此本文通过gitee举例。

    二. git使用

    2.1 git安装

    使用yum直接进行安装,命令示例为:sudo yum install git,直到shell提示Complete!即安装成功。如果sudo如今还不会使用,可以先登录root用户安装,或者通过上网搜索资料,将自身用户加入到可以信任名单中,本文将不再赘述。

    安装后可以输入指令git --version查看版本,如果有版本显示则安装成功。

    2.2 下载项目到本地仓库

    命令:git clone 仓库url

    将项目url填入后,输入相应信息认证,拉取本地仓库,可以发现本地会多出一个仓库文件,这就是下载下来的项目文件。示例如下:

    [lht@VM-12-7-centos code]$ git clone https://gitee.com/....../^^^^^^.git
    ......(省略部分内容)
    remote: Compressing objects: 100% (35/35), done.
    remote: Total 37 (delta 14), reused 0 (delta 0), pack-reused 0
    Unpacking objects: 100% (37/37), 70.40 KiB | 409.00 KiB/s, done.
    [lht@VM-12-7-centos code]$ ll
    total 16
    drwxrwxr-x 2 lht lht 4096 Oct 16 10:38 Blog_Compile
    drwxrwxr-x 2 lht lht 4096 Oct 30 23:03 Blog_Develope
    drwxrwxr-x 4 lht lht 4096 Oct 30 23:19 linux_-review
    drwxrwxr-x 4 lht lht 4096 Oct 24 22:12 test
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    2.3 文件上传

    文件上传主要有三步:git addgit commitgit push

    git add

    首先,将需要用 git 管理的文件告知 git,通过命令git add filename,示例如下:

    [lht@VM-12-7-centos linux_-review]$ touch testGit.c
    [lht@VM-12-7-centos linux_-review]$ vim testGit.c 
    [lht@VM-12-7-centos linux_-review]$ cat testGit.c 
    #include
    int main(){
            printf("hello Git!\n");
            return 0;
    }
    [lht@VM-12-7-centos linux_-review]$ git add testGit.c
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    git commit

    再用git commit .提交改动到本地,记得提交的时候应该注明提交日志, 描述改动的详细内容,添加方式为选项-m,示例如下:

    ###################   没有填写日记会出现这种情况  ###################
    [lht@VM-12-7-centos linux_-review]$ git commit 
    
    *** Please tell me who you are.
    
    Run
    
      git config --global user.email "you@example.com"
      git config --global user.name "Your Name"
    
    to set your account's default identity.
    Omit --global to set the identity only in this repository.
    
    fatal: unable to auto-detect email address (got 'lht@VM-12-7-centos.(none)')
    ########################   填写日记   ###############################
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    如果是第一次提交,可能会需要输入相应的登录信息,这时需要根据提示输入命令 git config --global user.email "you@example.com"git config --global user.name "Your Name",设置完成后回生成一个配置文件.gitconfig,其中就存在相应的配置,示例如下:

    [lht@VM-12-7-centos linux_-review]$ git commit -m "testGit"
    
    *** Please tell me who you are.
    
    Run
    
      git config --global user.email "you@example.com"
      git config --global user.name "Your Name"
    
    to set your account's default identity.
    Omit --global to set the identity only in this repository.
    
    fatal: unable to auto-detect email address (got 'lht@VM-12-7-centos.(none)')
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    再次进行提交操作

    [lht@VM-12-7-centos linux_-review]$ git commit -m "testGit"
    [master 67faee2] testGit
     1 file changed, 5 insertions(+)
     create mode 100644 testGit.c
    
    • 1
    • 2
    • 3
    • 4

    git push

    命令:git push

    输入命令后,输入登录信息,即可完成上传,示例与代码如下:

    [lht@VM-12-7-centos linux_-review]$ git push
    Username for 'https://gitee.com': liu-hongtao-1
    Password for 'https://liu-hongtao-1@gitee.com': 
    Enumerating objects: 4, done.
    Counting objects: 100% (4/4), done.
    Delta compression using up to 2 threads
    Compressing objects: 100% (3/3), done.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    image-20221031000306543

    2.4 其他

    其他命令

    • 查看状态:git status
    • 查看日志:git log
    • 查看版本:git --version

    .gitignore

    可以通过配置,进行对文件上传的筛选等功能


    补充:

    1. 代码将会放到:Linux_Review: Linux博客与代码 (gitee.com) ,欢迎查看!
    2. 欢迎各位点赞、评论、收藏与关注,大家的支持是我更新的动力,我会继续不断地分享更多的知识!
  • 相关阅读:
    陈芳允于1971年提出双星定位
    自娱自乐代码人的源码分析系列汇总
    inline的讨论——标准库的模板变量
    go proto 简单学习
    Android studio Mac 快捷键对应截图
    143.如何个性化推荐系统设计-3
    小黑leetcode之旅:86. 分隔链表
    应约凯程约稿
    2024/3/5打卡最长上升子序列**----线性DP,贪心,单调栈
    如何在CPU上进行高效大语言模型推理
  • 原文地址:https://blog.csdn.net/qq_66725576/article/details/127625389