Git 桌面中的 Squash 提交

Shw*_*elz 5 git github github-desktop

我正在尝试使用我已经推送到 GitHub 的分支将 6 个提交压缩为单个提交。

我尝试通过命令行执行此操作,但我一直收到 no-op 而不是该分支的提交。

有没有办法通过 GitHub 桌面来做到这一点,这可能更有意义?

如果可能,请逐步提供;

我是将 GitHub 用于协作目的的新手,而且我的知识并没有远远超过 git add、commit 和 push。

wha*_*ver 8

有没有一种方法可以通过 GitHub 桌面来做到这一点,可能更有意义?

从版本 2.9 开始,现在有一种方法可以压缩 GitHub Desktop 中的提交。

以下是执行此操作的两种便捷方法。

  1. 在“历史记录”选项卡中选择多个提交(使用CtrlShift键),右键单击所选提交之一并选择“Squash 2 commits...”。

在此输入图像描述

  1. 将一个分支合并到另一个分支时,单击右侧的箭头提交按钮,然后选择“压缩并合并”。

在此输入图像描述


Cod*_*ard 6

要进行 git 挤压,请按照下列步骤操作:

// X is the number of commits you wish to squash, in your case 6
git rebase -i HEAD~X
Run Code Online (Sandbox Code Playgroud)

一旦你压缩你的提交 - 选择sfor squash = 它将把所有提交合并到一个提交中。

在此输入图像描述


您还可以使用 --root 标志以备不时之需

尝试:git rebase -i --root

- 根

Rebase all commits reachable from <branch>, instead of limiting them with
an <upstream>.

This allows you to rebase the root commit(s) on a branch.  
When used with --onto, it will skip changes already contained in `<newbase>`   
(instead of `<upstream>`) whereas without --onto it will operate on every 
change. When used together with both --onto and --preserve-merges, all root 
commits will be rewritten to have `<newbase>` as parent instead.`
Run Code Online (Sandbox Code Playgroud)