簡體   English   中英

使用交互式變基壓縮時,Git 跳過合並提交

[英]Git skips merge commit when squashing using interactive rebase

我正在使用 git 開發一個功能,到目前為止我已經完成了以下步驟。

  • 基於master結帳名為feature1的新功能分支
  • 添加幾個提交。
  • 基於feature1簽出新的分支test
  • test執行一些更改。
  • 返回(結帳到) feature1分支。
  • test分支合並到feature1
  • 刪除test分支
  • 編輯文件,並修改最后一次提交以反映更改

這是git log --oneline -n 5輸出

de5d701 Merge branch 'test' into 'feature1' (amended)
a668f93 'feature1' commit3
ded7c00 'feature1' commit2
8731807 Initial 'feature1' commit
ff2f539 latest 'master' commit

我想在合並到master之前ff2f539 latest 'master' commit之后的所有內容。 我試着表演

git rebase --interactive  ff2f539

但最新的提交未在編輯器中列出:

pick 8731807 Initial 'feature1' commit
pick ded7c00 'feature1' commit2
pick a668f93 'feature1' commit3

# Rebase ff2f539..de5d701 onto ff2f539
#
# Commands:
...
# Note that empty commits are commented out

我不明白為什么跳過由合並test分支到feature1分支產生的最新提交。 保存並退出編輯器,內容如下:

pick 8731807 Initial 'feature1' commit
squash ded7c00 'feature1' commit2
squash a668f93 'feature1' commit3

# Rebase ff2f539..de5d701 onto ff2f539
#
# Commands:
...
# Note that empty commits are commented out

生成不提供上次提交更改的新提交

de5d701 Merge branch 'test' into feature1(amended)

他們失去了。 在合並到 master 之前如何將所有這些提交壓縮為一個單一提交有什么幫助嗎?

Git 按照設計不會在“交互式”列表中顯示合並提交。 相反,它包括由該合並帶入分支的所有提交。 您可以使用-p ( --preserve-merges ) 選項來更改該行為,但不建議在交互模式下使用,因為結果可能不那么明顯(請參閱http://git-scm.com/docs/git -rebase#_bugs )。

但是有一個簡單的解決方案,無需重新定位:

# make sure your working copy is clean, do git stash if needed
git checkout feature1
git reset --soft ff2f539
git commit -m "..."

這將產生一個提交,包括 ff2f539 之后的所有更改。

如果要在 rebase 中包含合並提交,請將--preserve-merges選項傳遞給git rebase

暫無
暫無

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

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