git

Git

Git is a free and open source distributed version control system.

Posted by LXG on April 19, 2019

Git官网

Git教程-官网

GIT架构-简书

GIT架构

GIT的架构,可以分为几个部分:

  1. 本地工作区(working directory)
  2. 暂存区(stage area, 又称为索引区, index)
  3. 本地仓库(local repository)
  4. 远程仓库副本
  5. 远程仓库(remote repository)

git_arch

.git


$ tree -L 1
.
├── branches
├── COMMIT_EDITMSG
├── config
├── description
├── FETCH_HEAD
├── gitk.cache
├── HEAD
├── hooks
├── index
├── info
├── logs
├── objects
├── ORIG_HEAD
├── packed-refs
└── refs

ssh环境配置

  1. git config –global user.name “lxg”
  2. git config –global user.email “lxg@gmail.com”
  3. ssh-keygen
  4. cd ~/.ssh
  5. cat ~/.ssh/id_rsa.pub
  6. copy to gerrit or gitlab or github

git tag

查看tag

  1. git tag
  2. git tag -ln
  3. git show v1.1.1
  4. git checkout v1.1.1

新增tag

  1. git add .
  2. git commit -m “”
  3. git tag -a v1.1.1 -m “”
  4. git push origin v1.1.1

删除tag

  1. git tag -d v1.1.1
  2. git push origin –delete tag v1.1.1

git merge

git merge –no-ff sunmi/l2_release

分支重命名

  1. git branch -m oldName newName
  2. git push –delete origin oldName
  3. git push origin newName
  4. git branch –set-upstream-to origin/newName

Git 仓库迁移

git clone –mirror https://github.com/xxxxxxx/oldProject.git cd oldProject.git git remote set-url –push origin https://github.com/xxxxxxx/newProject.git git push –mirror

大文件下载

  1. git config –global core.compression 0 关闭压缩
  2. git clone –depth 1 url 下载最近一次提交
  3. git fetch –unshallow 获取完整库
  4. git pull –all 获取状态

上边的方法只能拉取主分支,拉取其他分支的方法

  • git remote set-branches origin ‘remote_branch_name’
  • git fetch –depth 1 origin remote_branch_name
  • git checkout remote_branch_name
  • git fetch –unshallow