避免将不需要的本地历史推送到 Bazaar 或 Mercurial 中的主存储库
我是 DVCS 新手,所以我可能误解了一些概念和术语,但这就是我想要实现的想法,我试图找出 Bazaar 或 Mercurial 是否以直接的方式支持这一点:
有一个包含经过良好测试的代码的主存储库。假设我将其克隆(或拉取或分支或任何术语)到本地存储库,然后每天当我处理代码时,我会在本地提交更改,有时一天多次。
完成所有更改和测试后,我只想获取放入主存储库的每个文件的最新(本地)提交版本,没有我在本地提交的数十个中间版本在调试和单元测试期间。
从我读到的内容来看,显然,如果我推送这些半生不熟的版本的整个历史都会反映在主存储库中。一些互联网文章似乎表明,如果处理得当,rebase 可能会解决这个问题,但目前还不清楚是否/如何做到这一点,因为看起来 rebase 更多的是为了避免分叉的分支/合并历史,而不是避免提交一大组中间版本。
I'm new to DVCS so I'm probably misunderstanding some concepts and terminology, but this is the idea of what I'm trying to achieve, and I'm trying to find out if either Bazaar or Mercurial supports this in a straightforward manner:
There is main repository with well-tested code. Say I clone (or pull or branch or whatever the terminology is) from that into a local repository, then every day as I work on the code I commit changes locally, sometimes multiple times a day.
After I'm done with all my changes and testing, I want to get only the latest (locally) committed version of every file put into the main repository, without the dozens of intermediate versions that I committed locally during debugging and unit testing.
From what I've been reading, apparently the entire history of those half-baked versions would get reflected in the main repository if I push to it. Some internet articles seem to suggest that rebase might address that issue if it's handled right, but it's not so clear if/how that can be done, as it seems like rebase is more for avoiding a bifurcated branch/merge history than for avoiding the committing of a large set of intermediate versions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一些集市选项。
如果你想摆脱数十个本地提交,你实际上是在丢弃历史记录。一种方法是使用 bzr uncommit 命令。例如。
(在您进行主存储库的修订之前,请放弃修订。不要担心,它会告诉您将要做什么,并在执行之前与您确认)
然后你可以做一个新的提交,将所有其他提交合并为一个。
Bazaar 通常会隐藏合并的修订。将微小提交汇总到合并修订版中的一种方法是保留主存储库的本地分支/签出。然后,当您准备就绪时,将您的更改
bzr merge
到本地 main-repo-clone 中,然后提交合并的修订版。这样,您仍然保留所有历史记录,但所有小修订都会整齐地汇总到合并修订中。然后,您仍然可以在需要时查看该历史记录。
以下是如何不查看合并修订的示例:
以下是如何查看合并修订的示例:
Some bazaar options.
If you want to get rid of the dozens of local commits, you are actually throwing away history. One way of doing it is with the
bzr uncommit
command. eg.(Throw away rivisions until you get to the revision of the main repo. Don't worry it will show you what will be done and confirm with you before doing it)
Then you can do a new commit with all the others collapsed into one.
Bazaar normally hides merged revisions. One way for you to roll up your tiny commits into a merged revision is to keep a local branch/checkout of the main repo. Then when you are ready,
bzr merge
in your changes into your local main-repo-clone and then commit a merged revision.This way you still keep all your history but all the little revisions are neatly rolled up into a merge revision. You can then still see that history when you want.
Here is examples of how to not see merged revisions:
Here is examples of how to see merged revisions:
您要查找的关键字是 collapse 或 fold (Mercurial) 或 squash (Git)。恐怕我不知道芭莎里通常用什么术语来形容这个。
在 Mercurial 中,您可以使用 histedit 扩展(自 Mercurial 2.3 起捆绑的扩展)来折叠将一系列变更集合并为一个变更集。它提供了第三方折叠扩展中功能的超集。
rebase 扩展(另一个标准扩展)与
具有相同的功能 - -collapse
标志。您完全正确,通常进行变基以避免不必要的合并,但它在某种程度上也必须用于 在 Git 中折叠(和编辑)变更集。 Mercurial 的 histedit 扩展 是根据 Git 中的交互式 rebase 命令建模的。The keywords you're looking for are collapse or fold (Mercurial) or squash (Git). I'm afraid I don't know what the usual term is for this in Bazaar.
In Mercurial you can use the histedit extension (a bundled extension since Mercurial 2.3) to fold a series of changesets into a single changeset. It provides a superset of the functionality in the third-party collapse extension.
The rebase extension (another standard extension) has the same functionality with the
--collapse
flag. You're completely right that rebasing is normally done to avoid unnecessary merges, but it somehow also got to be used for collapsing (and editing) changesets in Git. The histedit extension for Mercurial is modeled after the interactive rebase commmand in Git.在 Bazaar 中,这是通过在本地主存储库的单独“克隆”(即
bzr 分支 URL
)来处理的,然后您可以通过多次提交来创建本地功能分支。当您准备好将该工作移至主存储库时,您可以将功能分支合并到主分支中。这会在主分支中留下一个修改后的工作树,然后您将其提交并推送到您的官方主存储库。此提交包括来自功能分支的修订历史记录,但它通常隐藏在bzr log
或其他日志历史记录视图中。In Bazaar, this is handled by having a separate "clone" (i.e.
bzr branch URL
) of the main repo locally and then you create local feature branches from that in which you do your work with multiple commits. When you're ready to move that work into the main repo, youbzr merge
the feature branch into the main branch. That leaves you with a modified working tree in the main branch which you then commit and push to your official main repo. This commit includes the revision history from your feature branch but it's normally hidden inbzr log
or other log history views.