DAILY DOCDAILY DOC
Rust
Node
Notes
Ubuntu
Leetcode
  • it-tools
  • excalidraw
  • linux-command
Rust
Node
Notes
Ubuntu
Leetcode
  • it-tools
  • excalidraw
  • linux-command
  • BFC 块级格式化上下文
  • Note
  • WebAssembly
  • public api
  • 位运算
  • bitwise operator
  • css实现隐藏效果
  • css snippets
  • 抖音点赞
  • js 相等判断
  • fetch ReadableStream
  • git
  • Github Actions 工作流
  • google search
  • RPC vs HTTP
  • gravatar
  • hhkb
  • Init project
  • input 文件上传
  • mac

    • Mac 使用技巧
    • alfred
    • mac shortcuts
    • shortcuts text edit
    • mac 修改host
  • 微前端
  • mock
  • nginx dump
  • nginx
  • NirCmd
  • npm
  • Operator Precedence
  • package.json
  • url query 解析
  • pnpm
  • JavaScript Precise countdown
  • react 模版
  • regexp
  • setup web development
  • telegram

    • telegram bot
  • timeFunction ease
  • 视频裁剪
  • vscode

    • vscode 高级指南
    • bracketPairs
    • jsconfig.json
    • vscode pipe into code
    • social project
    • vscode tasks
  • draggable resizable
  • windows 激活
  • 前端截图实现
  • 文本配音 富文本实现
  • 图片处理
  • 前端坐标
  • 定时任务
  • work efficient
  • 微信小程序动画实现方案
  • 排列组合
  • 数列
  • 语音驱动文字
  • 浏览器
  • 状态管理
  • 移动盒子
  • 移动端开发常用snippets
  • 设计模式
  • web performance

git

git config

查看配置

git config --list
detail
init.defaultbranch=master  # git config --global init.defaultbranch=master
user.email=xxx@xxxx.com
user.name=xxx

name email 为一个账户配置则无需 --global

git config --global user.name "xxx"
git config --global user.email "xxx"

git squash

git 代码合并,压缩commit

要将 Git 中的 a 分支代码合并到 b 分支,并将所有的 commit 记录合并为一个提交,可以使用 git merge --squash 命令。这种方法会将 a 分支的所有更改压缩成一个单一的 commit。以下是详细步骤:

  1. 切换到目标分支 b:

    git checkout b
    
  2. 使用 git merge --squash 将 a 分支的更改合并到 b 分支:

    git merge --squash a
    

    这条命令会将 a 分支上的所有更改应用到 b 分支上,但不会立即创建新的 commit。

  3. 创建一个新的 commit:

    git commit -m "Merged changes from branch 'a' into 'b'"
    

    您可以在提交信息中写上合并的说明。

示例

假设 a 分支有多个 commit,现在我们要将这些 commit 合并到 b 分支上并且只生成一个新的 commit。

  1. 切换到 b 分支:

    git checkout b
    
  2. 将 a 分支的更改合并(压缩)到 b 分支:

    git merge --squash a
    

    输出类似于以下内容:

    Squash commit -- not updating HEAD
    Automatic merge went well; stopped before committing as requested
    
  3. 创建一个新的 commit:

    git commit -m "Merged changes from branch 'a' into 'b'"
    

    现在,所有来自 a 分支的更改都被合并到 b 分支中,并以一个单一的 commit 提交。

验证合并

您可以使用 git log 查看 b 分支的历史记录,确保合并操作正确执行:

git log

您应该能看到合并的单一 commit,其中包含来自 a 分支的所有更改。

注意事项

  • 确保在合并之前同步分支: 在合并之前,确保 b 分支和 a 分支都是最新的。可以使用 git pull 更新分支。
  • 冲突解决: 如果在 git merge --squash 过程中发生冲突,需要手动解决冲突并继续完成合并。

通过这种方式,您可以有效地将一个分支的所有更改压缩成一个单一的 commit 并合并到另一个分支。

Refer

  • github get-started
  • github setting-your-commit-email-address
Last Updated:
Contributors: rosendo
Prev
fetch ReadableStream
Next
Github Actions 工作流