修剪Git提交/压缩Git历史 [英] Trimming Git Commits/Squashing Git History

查看:145
本文介绍了修剪Git提交/压缩Git历史的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我每隔几分钟检查我的代码到一个Git分支中,最后的评论就像是一切再次破裂以及其他荒谬之处。



然后,每隔几分钟/几小时/几天,我会认真提交一个真正的评论,例如第三次修正错误#22.55。 我怎样才能将这两个概念分开?我希望能够删除我所有的频繁提交,并留下严重的提交。

解决方案

使用壁球而不是

最近,我一直在另一个分支中工作,并使用壁球。另一个分支称为temp,然后使用 git merge temp --squash 将其引入推送到服务器的真正分支。



假设我在 Ticket65252 中工作流程是这样的:

  git branch -d temp #remove old temp bbranch 
git checkout -b temp
#工作工作,一路提交
git checkout Ticket65252
git merge temp --squash
git commit -m这里有一些消息

使用 rebase 的优势?方式不那么复杂。

使用 reset --hard 然后的优点重置--soft ?不易混淆,且容易出错。


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.

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.

解决方案

Using Squash Instead

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.

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"

Advantages over using rebase? Way less complicated.

Advantages over using reset --hard and then reset --soft? Less confusing and slightly less error prone.

这篇关于修剪Git提交/压缩Git历史的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆