git使用总结

Git

source: 狂神说 https://www.bilibili.com/video/BV1FE411P7B3?p=14

基础理论

git本地有三个工作区域:工作目录,暂存取(stage,index),资源库。还有远程的git仓库

  1. 在工作目录添加、修改文件 UserMapper.xml

  2. 将需要进行版本管理的文件放入暂存区域 git add.

  3. 将暂存区域的文件提交到git仓库 git commit

img

git项目搭建

  1. 本地创建新的仓库

    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/
    
    
  2. 克隆远程仓库

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(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

  1. ssh链接clone仓库
  2. 新建idea项目
  3. 将clone的文件夹中的内容都拷贝到新建项目文件夹中
  4. git add . 添加到暂存区
  5. git commit “message”
  6. 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]

一般在新建的工作分支上进行工作,当版本稳定之后,合并发布发到主分支

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值