Git基础操作
Git初始配置
1 2 3 4 5 6 7 8 9 10 11 12
| $ git config --global user.name "Zera7ul" $ git config --global user.email "yefangshun@sina.com" $ ssh-keygen -t rsa -C "yefangshun@sina.com" $ git config --global http.https://github.com.proxy http://127.0.0.1:7890 $ git config --global https.https://github.com.proxy http://127.0.0.1:7890 $ git config --global http.https://github.com.proxy socks5://127.0.0.1:7890 $ git config --global https.https://github.com.proxy socks5://127.0.0.1:7890 $ git config --global --unset http.proxy $ git config --global --unset https.proxy $ git config --global --unset http.https://github.com.proxy $ git config --global --unset https.https://github.com.proxy $ git config --global -l
|
进入GitHub_Settings_keys](https://github.com/settings/keys) ,新建new SSH Key,复制C:\Users\Administrator\.ssh\id_rsa.pub(linux密钥在~/.ssh)的内容
创建本地仓库
1 2 3 4 5
| $ cd /D/Documents/GitHub $ mkdir MyHexo $ cd MyHexo $ pwd /D/Documents/GitHub/MyHexo
|
1 2 3 4
| $ git init Initialized empty Git repository in /D/Documents/GitHub/MyHexo/.git/ $ ls -ah ./ ../ .git/
|
提交文件到本地仓库
1 2 3
| $ echo "# MyHexo" >> README.md $ git add README.md $ git commit -m "first commit"
|
同步到远程仓库
在Github新建同名远程仓库
1 2
| $ git remote add origin git@github.com:Zera7ul/MyHexo.git $ git push -u origin master
|
- origin 并不是指得是远程的仓库,而是指得是远程仓库在本地的一个指针
- 比如命令:
git merge origin master指的就是将本地的远端分支与本地的master 分支进行合并
从远程库克隆到本地
1
| $ git clone git@github.com:Zera7ul/MyHexo.git
|
版本控制
1 2 3 4 5 6 7 8 9 10
| $ git log $ git log --pretty=oneline $ git reset --hard HEAD^ $ git reset --hard 1094a... $ git reflog $ git status $ git checkout -- README.md $ git reset HEAD README.md $ rm <file> $ git rm <file>
|
分支管理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| $ git checkout -b dev Switched to a new branch 'dev'
$ git branch * dev master $ git checkout master $ git merge dev $ git branch -d dev
$ git switch -c dev $ git switch master
$ git log --graph
|
删除本地仓库
1 2 3
| $ ls -a $ find . -name ".git" | xargs rm -Rf $ rm -rf .git
|
安装GitLab社区版
1 2
| sudo yum install gitlab-ce #自动安装最新版 sudo yum install gitlab-ce-x.x.x #安装指定版本
|
GitLab常用命令
1 2 3 4 5 6 7 8
| sudo gitlab-ctl start # 启动所有 gitlab 组件; sudo gitlab-ctl stop # 停止所有 gitlab 组件; sudo gitlab-ctl restart # 重启所有 gitlab 组件; sudo gitlab-ctl status # 查看服务状态; sudo gitlab-ctl reconfigure # 启动服务; sudo vim /etc/gitlab/gitlab.rb # 修改默认的配置文件; gitlab-rake gitlab:check SANITIZE=true --trace # 检查gitlab; sudo gitlab-ctl tail # 查看日志;
|
参考:廖雪峰的Git教程