Git、GitHub、Gitee、GitLab
Git
Git,分布式版本管理工具
Linux 源码安装
# 下载源代码
wget -c https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.43.0.tar.gz .
tar zxvf git-2.43.0.tar.gz
./configure # 安装位置默认即可
configure: Setting lib to 'lib' (the default)
configure: Will try -pthread then -lpthread to enable POSIX Threads.
configure: CHECKS for site configuration
checking for gcc... no
checking for cc... no
checking for cl.exe... no
checking for clang... no
configure: error: in `/root/git/git-2.43.0':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
# 缺少gcc
yum install gcc-c++
# 再次运行 ./configure
make
# In file included from oss-fuzz/fuzz-commit-graph.c:1:0:
# ./git-compat-util.h:1495:18: fatal error: zlib.h: No such file or directory
# include <zlib.h>
# 解决:yum install zlib-devel
make install
git --version
# git version 2.43.0
常用命令
命令名称 | 作用 |
---|---|
git config --global user.name lizhengnan | 设置用户签名 |
git config --global user.email lzn122614@vip.qq.com | 设置用户签名 |
git init | 初始化本地库 |
git status | 查看本地库状态 |
git add file | 添加文件到暂存区 |
git rm --cached file | 删除暂存区的文件 |
git commit -m “description” file | 将暂存区的文件提交到本地库 |
git reflog | 查看版本信息 |
git log | 查看版本详细信息 |
git reset --hard version | 版本穿梭 |
分支操作
命令名称 | 作用 |
---|---|
git branch 分支名 | 创建分支 |
git branch -v | 查看分支 |
git checkout 分支名 | 切换分支 |
git merge 分支名 | 把指定的分支合并到当前分支上 |
合并冲突(两个分支对同一个文件同一处做了不同修改),需要查看文件,手动合并—> git add filename —> git commit -m “description” (此处不加文件名)
GitHub
GitHub,代码远程库。
- 创建远程库
远程库常用操作命令
命令 | 作用 |
---|---|
git remote -v | 查看当前所有远程地址别名 |
git remote add 库别名 远程库地址 | 给远程库创建别名 |
git push 远程库别名/地址 分支名称 | 推送本地分支到远程库 |
git pull 远程库别名/地址 远程库分支名 | 将远程库的某个分支最新内容拉取下来后与当前本地分支直接合并 |
git remote add Rplot https://github.com/zhengnanlee/R_Plot.git
git push Rplot master
# git: 'remote-https' is not a git command. See 'git --help'.
# 解决
# 安装 libcurl-devel、curl-devel ,然后重新编译 git (系统:CentOS Linux release 7.9.2009)
yum install libcurl-devel
yum install curl-devel
make clean
rm -r /usr/local/bin/git /usr/local/libexec/git-core
# 安装后重新编译安装 git
git push Rplot master
# Username for 'https://github.com': zhengnanlee
# Password for 'https://zhengnanlee@github.com':
# remote: Support for password authentication was removed on August 13, 2021.
# remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
# fatal: Authentication failed for 'https://github.com/zhengnanlee/R_Plot.git/'
- 生成ssh密钥
ssh-keygen -t rsa -C 'lzn122614@vip.qq.com'
# 连续3次回车
cat ~/.ssh/id_rsa.pub
# 拷贝
# GitHub --> settings --> SSH and GPG keys --> New SSH key
- 安装Git Credential Manager (GCM)
wget -c https://github.com/git-ecosystem/git-credential-manager/releases/download/v2.4.1/gcm-linux_amd64.2.4.1.tar.gz .
tar -xvf gcm-linux_amd64.2.4.1.tar.gz -C /usr/local/bin
git-credential-manager configure
# Process terminated. Couldn't find a valid ICU package installed on the system. Please install libicu (or icu-libs) using your package manager and try again. Alternatively you can set the configuration flag System.Globalization.Invariant to true if you want to run with no globalization support. Please see https://aka.ms/dotnet-missing-libicu for more information.
yum install -y libicu
# 再次运行
git-credential-manager configure
安装完GCM后,再次进行psuh/pull等操作
# 添加远程库别名
git remote add Rplot-ssh git@github.com:zhengnanlee/R_Plot.git
# push
git push Rplot-ssh master
# pull
git pull Rplot-ssh master
Gitee
- 账号创建
- 远程库创建
- pycharm 安装gitee插件并登录
- 命令操作与GitHub一样
- 从GitHub中导入仓库到Gitee
GitLab
GitLab,,局域网内使用Git作为代码管理工具的web服务。
- 安装 方法
https://about.gitlab.com/install/#centos-7
- 命令操作与GitHub一样