如何将多个提交合并为一个而不丢失历史记录

发布于 2024-11-10 18:41:38 字数 156 浏览 5 评论 0原文

我在一个分支中有多个提交。当我推送这些提交进行代码审查时,我们的代码审查工具会为每个提交创建一次审查。

为了避免这种情况,我想将多个提交合并到一个提交中。同时我不想丢失提交的历史记录。是否可以创建一个仅用于审核的新分支,并将主分支中的所有提交合并到审核分支中的单个提交?我该怎么做?

I have multiple commits in one branch. When I push these commits for code review, our code review tool creates one review for each commit.

To avoid this I want to merge multiple commits to a single commit. At the same time I don't want to lose the history of commits. Is it possible to create a new branch only for review and combine all the commits in my master branch to a single commit in my review branch? How do I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

病女 2024-11-17 18:41:38

我不知道你的审查工具,但这可能有效

git checkout review
git merge --squash master

http: //www.kernel.org/pub/software/scm/git/docs/git-merge.html

I dont know your review tool, but this may work

git checkout review
git merge --squash master

http://www.kernel.org/pub/software/scm/git/docs/git-merge.html

就是爱搞怪 2024-11-17 18:41:38

不想这样做。从你如何提交的意义上来说,实际的历史是毫无价值的。适合审查大小的块很有趣,因此只需 rebase -i 您的工作分支即可将提交合并到可管理大小且最重要的逻辑块,将它们发布以进行审查并忘记原始内容历史。

也就是说,要合并提交,您可以使用:

git merge --squash

Git 不会丢弃历史记录。它实际上也不会在 rebase 中执行此操作,但在这种情况下,历史记录的先前版本只能通过“reflog”进行访问,并且仅当您的 reflog 已过期(IIRC 默认情况下为 90 天) ),它最终将变得无法访问,并且 git gc 会将其丢弃。但通过挤压,原始分支仍然保留在那里,您仍然可以从引用日志中命名修订版本。

但是,审阅的历史记录将通过审阅工具合并到中央主控中,没有人会看到您的原始历史记录。你可以保留它,但它不会与官方的相关,而且无论如何也没有人会看它。

You do not want to do it. The actual history in the sense of how you did the commit is worthless. The suitably-sized-for-review chunks are interesting, so just rebase -i your working branch to combine the commits to manageably-sized and most importantly logical chunks, post them to review and forget about the original history.

That said, to combine the commits, you can use:

git merge --squash

Git will not throw away the history. It does not actually do that in rebase either, but in that case the previous version of the history only remains accessible through the "reflog" and only if you have expiration for reflogs (IIRC it's 90 days by default), it will eventually become inaccessible and git gc will throw it away. But with the squash, the original branch simply remains there and you can still name the revision from reflog.

However the reviewed history will be merged to the central master by the review tool and nobody will ever see your original history. You can keep it around, but it will not be related to the official one and nobody will ever look at it anyway.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文