如何将多个提交合并为一个而不丢失历史记录
我在一个分支中有多个提交。当我推送这些提交进行代码审查时,我们的代码审查工具会为每个提交创建一次审查。
为了避免这种情况,我想将多个提交合并到一个提交中。同时我不想丢失提交的历史记录。是否可以创建一个仅用于审核的新分支,并将主分支中的所有提交合并到审核分支中的单个提交?我该怎么做?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道你的审查工具,但这可能有效
http: //www.kernel.org/pub/software/scm/git/docs/git-merge.html
I dont know your review tool, but this may work
http://www.kernel.org/pub/software/scm/git/docs/git-merge.html
您不想这样做。从你如何提交的意义上来说,实际的历史是毫无价值的。适合审查大小的块很有趣,因此只需
rebase -i
您的工作分支即可将提交合并到可管理大小且最重要的逻辑块,将它们发布以进行审查并忘记原始内容历史。也就是说,要合并提交,您可以使用:
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 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 andgit 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.