千家信息网

如何进行git的下载、安装以及配置

发表于:2024-10-13 作者:千家信息网编辑
千家信息网最后更新 2024年10月13日,如何进行git的下载、安装以及配置,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。第一:git的介绍git(读音为/gɪt
千家信息网最后更新 2024年10月13日如何进行git的下载、安装以及配置

如何进行git的下载、安装以及配置,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

第一:git的介绍

git(读音为/gɪt/。)是一个开源的分布式版本控制系统可以有效、高速地处理从很小到非常大的bai项目版本管理。Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件。

第二:git的下载和安装

下载的部分在官网下载即可,这里下载的是git-1.7.7.4.tar.gz

[root@localhost ~]# tar zxvf git-1.7.7.4.tar.gz[root@localhost ~]# cd git-1.7.7.4[root@localhost git-1.7.7.4]# ./configure[root@localhost git-1.7.7.4]# make && make install

安装好之后查看以上没加入.configure时的默认安装目录

[root@localhost ~]# which git //这个路径在PATH内,故不需要再添加

/usr/local/bin/git

这样git就安装成功了

第三:git的基本配置(这里root登录)

[root@localhost /]# mkdir -p /git/project[root@localhost /]# cd /git/project/[root@localhost project]# git config –global user.name ‘ethnicitybeta’[root@localhost project]# git config –global user.email ‘ethnicitybeta@126.com’

Global的配置其实是写入用户的家目录中的git配置文件中

[root@localhost project]# cat ~/.gitconfig[user]

name = ethnicitybeta

emal = ethnicitybeta@126.com

email =

[root@localhost project]# vim main.c //创建测试文件

Hello ethnicitybeta!!!

[root@localhost project]# git init //git的初始化

Initialized empty Git repository in /git/project/.git/

[root@localhost project]# ls -al

total 32

drwxr-xr-x 3 root root 4096 Nov 27 03:38 .

drwxr-xr-x 3 root root 4096 Nov 27 03:11 ..

drwxr-xr-x 7 root root 4096 Nov 27 03:38 .git

-rw-r–r– 1 root root 23 Nov 27 03:37 main.c

接下来这段是相对于全局设置的局部设置

[root@localhost project]# git config user.name ‘ethniciy’[root@localhost project]# git config user.email ‘ethnicity@126.com’[root@localhost project]# cat .git/config[core]

repositoryformatversion = 0

filemode = true

bare = false

logallrefupdates = true

[user]

email = ethnicity@126.com

name = ethnicity

第四:一个git实例

[root@localhost project]# vim main.c //创建测试文件

Hello ethnicitybeta!!!

[root@localhost project]# git init //git的初始化[root@localhost project]# git add . //加入到git[root@localhost project]# ll .git/ //下边出现的index就是Staging area

total 72

-rw-r–r– 1 root root 23 Nov 27 03:38 HEAD

drwxr-xr-x 2 root root 4096 Nov 27 03:38 branches

-rw-r–r– 1 root root 143 Nov 27 03:41 config

-rw-r–r– 1 root root 73 Nov 27 03:38 description

drwxr-xr-x 2 root root 4096 Nov 27 03:38 hooks

-rw-r–r– 1 root root 104 Nov 27 03:43 index

drwxr-xr-x 2 root root 4096 Nov 27 03:38 info

drwxr-xr-x 5 root root 4096 Nov 27 03:43 objects

[root@localhost project]# git commit -m ‘1st commit’ //提交生成第一个commit[master (root-commit) 96f025b] 1st commit

1 files changed, 1 insertions(+), 0 deletions(-)

create mode 100644 main.c

[root@localhost project]# rm -rf main.c //模拟一个文件丢失[root@localhost project]# git checkout -f HEAD //找回丢失的文件[root@localhost project]# ls

main.c

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注行业资讯频道,感谢您对的支持。

0