簡體   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