簡體   English   中英

如何將7個推送的提交壓縮成1到1的git?

[英]How to squash 7 pushed commits into one in to 1 in git?

我已經嘗試了多種方法來壓縮我的遠程repo提交,但沒有把它弄好。 我想把它們全部壓扁並制成一個。 以下是提交列表。 下面是我對上游的拉取請求的摘要(列出了7次提交)。 我想只列出一個而不是7個。

在此輸入圖像描述

git reset --soft HEAD~7
git add --all
git commit
git push --force

首先,將git index重置為要壓縮的提交之前。 使用--soft以便git只重置索引並且不會觸及您的工作目錄。 然后像往常一樣創建一個提交。

另一種方法是使用squash - 我的其他工作interactive rebase

為了做一個git squash,請按照以下步驟操作:

# X is the number of commits you wish to squash, in your case 7
# In this interactive rebase there can be more that 7 commits if
# there was a merge in one of them
git rebase -i HEAD~X

一旦你壓縮你的提交 - 選擇s為squash =它會將所有提交組合成一個提交。

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM