[英]Is it possible to rebase and edit a git commit without using interactive rebase?
[英]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.