修剪 Git 提交/压缩 Git 历史记录 [英] Trimming Git Commits/Squashing Git History
问题描述
我每隔几分钟左右就会将我的代码检查到一个 Git 分支中,而这些评论最终变成了诸如一切都坏了,重新开始"之类的荒谬言论.
I check my code into a Git branch every few minutes or so, and the comments end up being things like "Everything broken starting again" and other absurdities.
然后每隔几分钟/几小时/几天,我就会认真地提交一次真实的评论,例如已修复错误 #22.55,第 3 次".如何区分这两个概念?我希望能够删除所有频繁提交的内容,只留下严重的提交内容.
Then every few minutes/hours/days I do a serious commit with a real comment like, "Fixed bug #22.55, 3rd time." How can I separate these two concepts? I would like to be able to remove all my frequent-commits and just leave the serious ones.
推荐答案
改用 Squash
最近,我一直在另一个分支工作并使用 squash
.另一个分支称为 temp,然后我使用 git merge temp --squash
将其带入推送到服务器的实际分支中.
Recently, I've been working in another branch and using squash
. The other branch is called temp, and then I use git merge temp --squash
to bring it into the real branch that gets pushed to the server.
工作流程是这样的,假设我在 Ticket65252
中工作:
Workflow is something like this, assuming I'm working in Ticket65252
:
git branch -d temp #remove old temp bbranch
git checkout -b temp
# work work work, committing all the way
git checkout Ticket65252
git merge temp --squash
git commit -m "Some message here"
使用 rebase
的优势?不那么复杂.
Advantages over using rebase
? Way less complicated.
与使用 reset --hard
和 reset --soft
相比有什么优势? 更少混淆,更不容易出错.
Advantages over using reset --hard
and then reset --soft
? Less confusing and slightly less error prone.
这篇关于修剪 Git 提交/压缩 Git 历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!