[英]Git: How to squash all commits between two commits into a single commit
[英]How to squash all commits from a commit id?
我的開發分支上有很多提交,我想在創建合並請求之前將它們壓縮成一個提交。 我想壓縮來自 id: 9199ed7e53dbeeecbb9ef107e245f4d07b2ff257
的所有提交,包括最后一次提交: 6177ddbf5b8e681a028abd7c512ae6ccdc86e744
我想我需要使用git rebase interactive
,但我不想為 50 多次提交做一些手動工作:/有什么建議嗎?
在你的情況下,
# move head to the last commit
git reset 6177ddbf5b8e681a028abd7c512ae6ccdc86e744 --hard
# move head to 9199ed7e53dbeeecbb9ef107e245f4d07b2ff257 and keep all changes in the index
git reset 9199ed7e53dbeeecbb9ef107e245f4d07b2ff257 --soft
# amend the changes into 9199ed7e53dbeeecbb9ef107e245f4d07b2ff257
git commit --amend
這里我們可以使用稍微不同的方法,
# move head to the last commit
git reset 6177ddbf5b8e681a028abd7c512ae6ccdc86e744 --hard
# move head to 9199ed7e53dbeeecbb9ef107e245f4d07b2ff257's parent and keep all changes in the index
git reset 9199ed7e53dbeeecbb9ef107e245f4d07b2ff257~ --soft
# commit the changes
git commit
交互式變基也可以工作,但它需要更多的編輯。
# specify 9199ed7e53dbeeecbb9ef107e245f4d07b2ff257's parent as the base
git rebase -i 9199ed7e53dbeeecbb9ef107e245f4d07b2ff257~
# modify the "pick" from the 2nd line to the last line to "s" or "squash"
# with the help of editor like vim or vs code, it's easy to edit multiple lines
# save and quit
# edit the commit message
# save and quit
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.