Git
source: 狂神说 https://www.bilibili.com/video/BV1FE411P7B3?p=14
基础理论
git本地有三个工作区域:工作目录,暂存取(stage,index),资源库。还有远程的git仓库
-
在工作目录添加、修改文件 UserMapper.xml
-
将需要进行版本管理的文件放入暂存区域 git add.
-
将暂存区域的文件提交到git仓库 git commit
![img](/Users/pz/Desktop/Screen%20Shot%202020-05-26%20at%203.50.09%20PM.png)
git项目搭建
-
本地创建新的仓库
pz@ps-MacBook-Pro ~ % cd ~/Desktop/study/gitcode pz@ps-MacBook-Pro gitcode % git init Initialized empty Git repository in /Users/pz/Desktop/study/gitcode/.git/
-
克隆远程仓库
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-tAsQN4U9-1590542186674)(/Users/pz/Desktop/Screen Shot 2020-05-26 at 3.53.01 PM.png)]
$git clone [url]
常用命令
查看指定文件状态
$git status [filename]
查看所有文件状态
$git status
添加所有文件到暂存区
$git add .
提交暂存区中的内容到本地仓库
-m 代表提交信息
$git commit -m
ssh
pz@ps-MacBook-Pro gitcode % ssh-keygen -t rsa -C "pepperzhaopp@gmail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/pz/.ssh/id_rsa):
/Users/pz/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/pz/.ssh/id_rsa.
Your public key has been saved in /Users/pz/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:+sy+rWjyY9t5lnjy7leAYJBPs/LosS1UR/11qmdB6gg pepperzhaopp@gmail.com
The key's randomart image is:
+---[RSA 3072]----+
| .o . |
| . = . . . o|
| + = . + o.|
| . E o o + |
| =So o o . |
| +.. . o + |
| o.+ . . + |
| . B*+o= . |
| =+=X@=. |
+----[SHA256]-----+
idea+git
- ssh链接clone仓库
- 新建idea项目
- 将clone的文件夹中的内容都拷贝到新建项目文件夹中
- git add . 添加到暂存区
- git commit “message”
- git push
分支
pz@ps-MacBook-Pro gitcode % cd gitlearn
pz@ps-MacBook-Pro gitlearn % git branch
* master
pz@ps-MacBook-Pro gitlearn % git branch -r
origin/HEAD -> origin/master
origin/master
新建分支
$ git branch dev
切换分支
$ git checkout -b dev
多个分支如果并行执行,就会导致代码不冲突,即同时存在多个版本
分支交叉,合并指定分支到当前分支
$ git merge [branch]
如果同一个文件在合并分支时都被修改了则会引起冲突:解决方法时可以修改冲突文件后重新提交,选择保留他的代码还是你的代码
删除分支
$ git branch -d [branch-name]
一般在新建的工作分支上进行工作,当版本稳定之后,合并发布发到主分支