粥里有勺糖

vuePress-theme-reco 粥里有勺糖    2018 - 2023
粥里有勺糖 粥里有勺糖

Choose mode

  • dark
  • auto
  • light
关于我
备战春秋
  • 心得总结
  • 校招考点汇总
  • 面经汇总
  • 复习自查
技术笔记
  • 技术教程
  • 模板工程
  • 源码学习
  • 技术概念
  • 个人作品
  • 学习笔记
计算机基础
  • 算法与数据结构
  • 操作系统
  • 计算机网络
  • 设计模式
  • 剑指offer
大前端
  • javascript
  • vue
  • html
  • css
  • 🌏浏览器专题
  • Web性能优化
  • regexp
  • node
面试
  • 问解
  • javascript
  • css
  • 手撕代码
  • 性能优化
  • 综合问题
  • 面经汇总
  • 小程序
手撕代码
  • 数据结构与算法
  • javascript
  • css
个人站点
  • GitHub (opens new window)
  • 博客园 (opens new window)
  • 掘金 (opens new window)
线上作品
  • 轻取(文件收集) (opens new window)
  • 个人图床 (opens new window)
  • 考勤小程序 (opens new window)
  • 时光恋人 (opens new window)
  • 在线简历生成 (opens new window)
留言板
Github (opens new window)
author-avatar

粥里有勺糖

285

文章

40

标签

关于我
备战春秋
  • 心得总结
  • 校招考点汇总
  • 面经汇总
  • 复习自查
技术笔记
  • 技术教程
  • 模板工程
  • 源码学习
  • 技术概念
  • 个人作品
  • 学习笔记
计算机基础
  • 算法与数据结构
  • 操作系统
  • 计算机网络
  • 设计模式
  • 剑指offer
大前端
  • javascript
  • vue
  • html
  • css
  • 🌏浏览器专题
  • Web性能优化
  • regexp
  • node
面试
  • 问解
  • javascript
  • css
  • 手撕代码
  • 性能优化
  • 综合问题
  • 面经汇总
  • 小程序
手撕代码
  • 数据结构与算法
  • javascript
  • css
个人站点
  • GitHub (opens new window)
  • 博客园 (opens new window)
  • 掘金 (opens new window)
线上作品
  • 轻取(文件收集) (opens new window)
  • 个人图床 (opens new window)
  • 考勤小程序 (opens new window)
  • 时光恋人 (opens new window)
  • 在线简历生成 (opens new window)
留言板
Github (opens new window)
  • devlearn

    • 开发教程
    • 实践:利用ArrayBuffer实现预览指定目录下的所有文件的内容
    • 在linux-deepin上使用deepin-wine5完美运行腾讯会议/QQ/微信等此类应用
    • eslint插件开发教程
    • ServerLess之云函数实践-天气API
    • 移动端阻止弹窗下层页面被滑动
    • 小技巧:for of中获取index
    • Git常用的一些基本操作
    • 向页面注入js实现为图片和文字元素添加透明蒙层
    • 实践:使用jsencrypt配合axios实现非对称加密传输的数据
    • 封装dotenv库实现类似Vite加载环境变量的行为
    • 30行代码实现合并指定目录下的所有文件的内容
    • 马上中秋了,把鼠标指针变为小玉兔
    • Node中require与fs.readFile读取JSON文件的对比
    • 使用免费的七牛云OSS(10G)搭建个人的在线图床
    • 分享封装的一些七牛云OSS操作方法
    • 本地配置SSH免密远程登录服务器
    • 工具方法汇总
    • 腾讯云Serverless实践-Node.js服务部署
    • 腾讯云Serverless实践-静态网站托管
    • 为什么'\x1B'.length === 1?\x与\u知识延伸
    • Vite插件开发纪实:vite-plugin-monitor(上)
    • Vite插件开发纪实:vite-plugin-monitor(中)
    • Vite插件开发纪实:vite-plugin-monitor(下)
    • 解决Vite-React项目中js使用jsx语法报错的问题
    • webpack 项目接入Vite的通用方案介绍
    • webpack 项目接入Vite的通用方案介绍-草稿
    • 优雅的处理挂载window上的函数可能不存在的情况
    • Mac上抓包秒通关羊了个羊

Git常用的一些基本操作

vuePress-theme-reco 粥里有勺糖    2018 - 2023

Git常用的一些基本操作

粥里有勺糖 2020-09-02 技术笔记技术教程

# Git常用的一些基本操作

# 基本操作

初始化本地仓库

git init
1

跟踪文件|将改动放入暂存区

# 当前目录下的所有,不包括.gitignore中的文件或目录
git add . 
# 指定目录
git add dirPath
# 指定文件
git add filePath
# 指定多个文件
git add file1Path file2Path
1
2
3
4
5
6
7
8

将改动从暂存区中移除

git restore filename
1

撤销工作区指定文件的修改

# 还原到最近的commit状态
git checkout filename
1
2

将暂存区的内容提交到本地仓库

git commit -m "you can diy here content"
1

file 查看commit日志,提交历史

git log
# 带图像的查看
git log --graph
1
2
3

查看工作区当前状态

git status
1

查看查看命令历史

git reflog
1

查看指定文件的改动了哪些

git diff filename
# 查看工作区指定的文件与版本库中最新的代码有何区别
git diff HEAD -- filename
1
2
3

回退到之前的commit

  • tips:
    • HEAD表示当前版本
    • HEAD^表示前一版本
    • HEAD^^表示前两个版本,依次类推
# 当前的修改不会丢弃
git reset HEAD^

# 丢弃当前的更改
git reset HEAD^ --hard
1
2
3
4
5

# 删除文件相关

从本地仓库中取回被删除的文件

git checkout filename
# 命令本质的作用就是用最新的commit中的文件替换当前的文件 
1
2

从本地仓库中删除指定的文件

git rm filename
# 删除后需要commit过后才生效
git commit -m "del: delete a filename"
# 在commit之前想要恢复的话
# 第一步,先把修改弄到暂存区
git restore --staged filename
# 第二部,撤销暂存区的修改
git restore filename
1
2
3
4
5
6
7
8

# 远程仓库相关

创建本地的ssh key

ssh-keygen -t rsa -C "youremail@example.com"
1

本地仓库关联远程仓库

git remote add remoteName address
# remoteName 可以自行定义,可以关联多个远程仓库
# 一般主要的remote 使用 origin命名
1
2
3

插查看关联的远程仓库

# 只显示名称
git remote
# 显示远程仓库的地址
git remote -v
1
2
3
4

删除关联的远程仓库

git remote remove remoteName
1

重命名关联的远程仓库名称

git remote rename oldRemoteName newRemoteName
1

将本地分支推向远程仓库

# 全写
git push remoteName localBranchName:remoteBranchName
# 简写(这种情况默认本地与远程分支名称一致)
git push remoteName branchName
1
2
3
4

设置上游分支

git push -u remoteName branchName 
# 设置上游分支后
# 本地在push的时候就可以直接执行
git push
# 等价于
git push remoteName branchName
1
2
3
4
5
6

克隆远程仓库到本地

git clone remoteAddress
1

更新本地的分支列表

# 更新所有的远程仓库的
git fetch -all
# 更新指定远程仓库
git fetch remoteName
1
2
3
4

拉取/合并远程的分支到本地

git pull remoteName branchName
1

# 分支相关

创建分支

git branch newBranchName
1

切换分支

git checkout otherBranchName
1

创建并切换

git checkout -b newBranchName
1

合并分支

# 快速合并
# 将otherBranch分支合并到当前的分支
# 快速合并看不出来做过改动
git merge otherBranch
# 合并其它分支,将变动都放入暂存区,不合并commit
git merge otherBranch --squash
# 禁用快速合并
git merge --no-ff -m "commit msg" otherBranch
# 舍弃合并,尝试恢复到你运行合并前的状态
git merge --abort
1
2
3
4
5
6
7
8
9
10

合并其它分支的某个commit到当前分支

git cherry-pick commit_id
1

变基

rebase操作可以把本地未push的分叉提交历史整理成直线

git rebase branchName
1

删除分支

git branch -d branchName
1

switch

checkout 既可以切换分支又可以撤销修改,容易造成歧义,所以切换分支可以使用switch

# 切换分支
git switch branchName
# 创建并切换
git switch -c newBranchName
1
2
3
4

# stash

将工作区未提交的内容先存储起来

储存

# flagName 用于标示每次的stash操作
git stash save flagName
1
2

查看贮藏的列表

git stash list
1

恢复贮藏的内容

git stash pop stash_id
# or
git stash apply stash_id
# stash_id通过git stash list 获取
# 区别
# pop会在恢复后删除指定的stash
# apply不会删除
1
2
3
4
5
6
7

# 标签

给指定的commit打上一个标签,便于寻找关键的commit

# 默认为最新的commit打上tag
git tag v0.0.0
git tag youlikeText

# 为指定的commit 打上tag
git tag youlikeText commit_id
# commit_id通过git log获取
1
2
3
4
5
6
7

创建带有说明的标签

git tag -a tagName -m "description" comment_id
1

查看指定tag的说明内容

git show tagName 
1

查看所有标签

git tag
1

将本地的tag提交到远程仓库

git push --tag
1
Edit this page (opens new window)
Last Updated: 2022/5/15 12:46:34