CentOS 7离线安装使用git

一 CentOS 7下载安装配置git

1.1 下载安装

git下载地址

# 1 下载后上传到服务器/opt/software/git
cd /opt/software/git

# 2 解压
tar -zxvf git-2.34.1.tar.gz

# 3 配置安装目录
cd git-2.34.1/
./configure --prefix=/usr/local/git

# 4 编译安装
make && make install

1.2 配置环境变量

# 修改/etc/profile文件,修改如下。如果有多个PATH,中间用英文冒号隔开
vim /etc/profile
# 加上或修改如下两行
export GIT_HOME=/usr/local/git
export PATH=$PATH:$JAVA_HOME/bin:$GIT_HOME/bin
# 修改完重新加载配置文件
source /etc/profile

在这里插入图片描述

# 创建软链(因为安装位置不是默认的,不创建后面使用会报错)
ln -s /usr/local/git/bin/git-receive-pack /usr/bin/git-receive-pack
ln -s /usr/local/git/bin/git-upload-pack /usr/bin/git-upload-pack
# 报错信息
bash: git-receive-pack: command not found
fatal: Could not read from remote repository.
bash: git-upload-pack: command not found
fatal: Could not read from remote repository.

# 查看是否配置成功
git --version

1.3 git常用命令

命令名称作用
git config --global user.name 用户名设置用户签名(可使用cat ~/.gitconfig查看配置)
git config --global user.email 邮箱设置用户邮箱(可使用cat ~/.gitconfig查看配置)
git init初始化本地库
git status查看本地库状态
git add 文件名添加到暂存区
git commit -m “日志信息” 文件名提交到本地库
git reflog查看历史记录
git reset --hard 版本号版本穿梭

二 上传与下载

2.1 上传-服务器端(centos)操作

2.1.1 添加git用户

useradd git
passwd git

2.1.2 创建文件夹、初始化仓库

# 创建文件夹
mkdir -p /usr/local/git/repos/demo1
# 初始化仓库
git init --bare /usr/local/git/repos/demo1/
# 修改仓库文件所有者
chown -R git:git demo1/

在这里插入图片描述
其中,初始化后每个文件的用途如下(了解)

ls -a /usr/local/git/repos/demo1
branches 分支目录
config 定义项目特有的配置选项
description 仅供给git web使用
HEAD 指示当前的分支
hooks 包含git钩子文件
info 包含一个全局的排除文件
objects 存放所有的数据内容,有info pack
refs 存放指向数据的提交对象指针
index 保存暂存区的信息

2.1.3 修改仓库配置文件

# 初始化仓库之后,修改配置文件
vim /usr/local/git/repos/demo1/config
# 在最后面添加如下信息
[receive]
denyCurrentBranch = ignore

在这里插入图片描述

2.2 上传-本地端(windows)操作(也需要安装git)

# 0 准备工作,如果第一次使用git,执行如下指令。 //禁用自动转换 
git config --global core.autocrlf false
# 1 进入项目根目录,然后 git bash here打开窗口,输入指令 :
git init 
# . 表示该目录下的全部文件
git add .
git commit -m "第一次提交"
# 创建远程连接,其中demo1是连接的别名
git remote add demo1 git@IP:/usr/local/git/repos/demo1
# push,其中demo1是上面的别名,master是分支
git push demo1 master

2.3 拉取代码

# 在本地新建一个文件夹,进入文件夹,右键空白的地方,git bash here,然后:
git init
# 最后验证是否push成功,试试拉取pull
git clone git@IP:/usr/local/git/repos/demo1

三 其他操作

3.1 配置git忽略文件

在windows登录用户的home文件夹中新建git.ignore,内容如下:
常见的需要忽略的内容

# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see 
http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
.classpath
.project
.settings
target
.idea
*.iml

然后在登录用户的home文件夹下,找到并编辑隐藏文件 .gitconfig,在后面配置上面的git.ignore路径。

[core]
	excludesfile = C:/Users/华硕/git.ignore

在这里插入图片描述

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值