gitlab是常用的版本管理工具
相对于github来说,gitlab不收费,而且基本具有github的全部功能
fetch:将本地已有的工程从远端拉取到本地repository;clone:将本地没有的工程从远端拉取到本地repository;pull:直接将本地没有的工程从远端拉取到本地工作目录;checkout:将本地repository存储的某个版本作为工作目录;add:将本地的更改添加到索引中;commit:将索引中的修改一次性写入本地repository;push:将repository中的更改拉取到远端,实现版本非本地端备份;checkout和commit是相反动作,clone/fetch和push是相反动作;
在git中,我们使用git config 命令用来配置git的配置文件,git配置级别主要有以下3类:
1、仓库级别 local 【优先级最高】
2、用户级别 global【优先级次之】
3、系统级别 system【优先级最低】
git config --local -l 查看仓库配置
git config --global -l 查看用户配置
git config --system -l 查看系统配置
git config -l 查看所有的配置信息
git config 添加配置项目
git config --global user.email “you@example.com”git config --global user.name “Your Name”
构建repository几种方法
1.本地没有repository
git clone ssh://git@172.16.xxx.xxx:xxxx/test_file/test.git 从远程拉取repository到本地
cd test.git 进入test.git这个文件夹
touch README.md 建立 README.md 文件 用来书写开发记录
git add README.md 将本地 README.md 更改添加到索引中
git commit -m "add README" 将 README.md 索引中的修改一次性写入本地repository
git push origin xx 将本地文件推送到远程
2.本地没有repository
cd existing_folder 进入文件夹 这个文件夹将会为 repository
git init 进行初始化
git remote add origin ssh://git@172.16.xxx.xxx:xxxx/test_file/test.git 连接远程
touch README.md 建立 README.md 文件 用来书写开发记录
git add . 将本地更改添加到索引中
git commit -m "Initial commit" 将索引中的修改一次性写入本地repository
git push origin xx 将本地文件推送到远程
git branch 查看本地分支
git branch -r 查看远程分支
git branch [name] 创建本地分支
git checkout -b [name] 创建新分支并立即切换到新分支
git checkout [name] 切换分支
git branch -d [name] 删除分支
git push origin [name] 创建远程分支(本地分支push到远程)
git push origin --delete 删除远程分支
git show 获取项目的详细信息
git add . #或 git add * 提交所有文件 git add README.md #提交指定文件 git add folder/ #提交某个文件夹下面的所有文件
git reset --hard HEAD^ #回退到上个版本 git reset --hard HEAD~3 #回退到前3次提交之前,以此类推,回退到n次提交之前 git reset --hard commit_id #退到/进到 指定commit的sha码 git push origin HEAD --force #强推到远端,使用git push 推送推送失败
git rm 与 git reset的区别
git rm:用于从工作区和索引中删除文件
git rm file_path 删除暂存区和分支上的文件,同时工作区也不需要 git rm --cached file_path 删除暂存区或分支上的文件, 但工作区需要使用, 只是不希望被版本控制
git reset:用于将当前HEAD复位到指定状态。一般用于撤消之前的一些操作(如:git add,git commit等)
1.x版本
.git add all 可以提交未跟踪、修改和删除文件
.git add . 可以提交未跟踪和修改文件,但是不处理删除文件
2.x版本
.git add all无论在哪个目录执行都会提交相应文件
.git add .只能够提交当前目录或者它后代目录下相应文件
The most commonly used git commands are: add Add file contents to the index bisect Find by binary search the change that introduced a bug branch List, create, or delete branches checkout Checkout a branch or paths to the working tree clone Clone a repository into a new directory commit Record changes to the repository diff Show changes between commits, commit and working tree, etc fetch Download objects and refs from another repository grep Print lines matching a pattern init Create an empty Git repository or reinitialize an existing one log Show commit logs merge Join two or more development histories together mv Move or rename a file, a directory, or a symlink pull Fetch from and merge with another repository or a local branch push Update remote refs along with associated objects rebase Forward-port local commits to the updated upstream head reset Reset current HEAD to the specified state rm Remove files from the working tree and from the index show Show various types of objects status Show the working tree status tag Create, list, delete or verify a tag object signed with GPG
