git

时间:2022-07-26
本文章向大家介绍git,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

GIT是一个分布式版本管理系统,速度快,适合大规模,跨地区多人协同开。SVN是一个集中式版本管理系统。

GIT分布式版本管理系统

Gitlab git私库解决方案

Github git公有库解决方案

git安装

Centos:

yum install -y git

Ubuntu:

apt-get install git

Windows安装git bash

linux编译安装

#安装依赖包
[root@localhost ~]# yum install -y curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker

[root@localhost ~]# unzip v2.7.4.zip
[root@localhost ~]# cd git-2.7.4/
[root@localhost git-2.7.4]# make prefix=/usr/local/git all
[root@localhost git-2.7.4]# make prefix=/usr/local/git install
[root@localhost git-2.7.4]# rm -f /usr/bin/git
[root@localhost git-2.7.4]# ln -s /usr/local/git/bin/git /usr/bin/git
[root@localhost git-2.7.4]# git --version
git version 2.7.4

初始化仓库

[root@localhost ~]# mkdir test && cd test
[root@localhost test]# git init
[root@localhost test]# git config --global user.name "test"
[root@localhost test]# git config --global user.email test@qq.com
[root@localhost test]# git config --list
user.name=test
user.email=test@qq.com
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
四个区域:
远程仓库<-->本地仓库<-->暂存区域<-->工作目录
四种状态
Untracked、Unmodified、Modified、Staged
Untracked(工作目录)-->git add -->Staged(暂存区)-->git commit版本-->Unmodified(本地仓库)-->Edit file-->Modified-->Stage the file-->Staged
常用命令
git add 加入暂存
git status 查看状态
git status -s 状态概览
git diff 尚未暂存的文件
git diff --staged 暂存区文件
git commit 提交更新
git reset 回滚
git rm 从版本库中移除
git rm --cached README 从暂存区中移除
git mv 相当于mv git rm git add 三个命令

分支命令

git branch例出分支
git branch -v
git branch --merged查看哪些分支被合并
git branch --no-merged查看哪些分支未被合并
git branch -d testling删除分支
git checkout切换分支
git merged融合分支