繁体   English   中英

在 Git 桌面中压缩提交

[英]Squash Commits in Git Desktop

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

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

有没有一种方法可以通过 GitHub 桌面执行此操作更有意义?

如果可能,请逐步提供;

我不熟悉将 GitHub 用于协作目的,我的知识范围并不超过 git add、commit 和 push。

要执行 git squash,请按照以下步骤操作:

// X is the number of commits you wish to squash, in your case 6
git rebase -i HEAD~X

压缩提交后 - 选择s表示压缩 = 它将所有提交合并为一个提交。

在此处输入图像描述


您还可以使用 --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.`

有没有一种方法可以通过 GitHub 桌面执行此操作更有意义?

从 2.9 版开始,现在可以在 GitHub Desktop 中压缩提交。

这里有两种方便的方法可以做到这一点。

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

在此处输入图像描述

  1. 将一个分支合并到另一个分支时,单击右侧的箭头以提交按钮并选择“Squash and merge”。

在此处输入图像描述

Thoughtbot 的这篇文章可能会帮助您通过命令行完成它。 确切地知道您在做什么可能比依赖 Git 的 GUI 工具更好。 从长远来看,这将使您受益。

https://thoughtbot.com/blog/git-interactive-rebase-squash-amend-rewriting-history

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM