将 Git 工作流程转换为 Mercurial
我已经使用 Git 一段时间了,我想将我常用的工作流程转换为 Mercurial。特别是,我有兴趣转换用于为 Git 项目做出贡献的工作流程,以便能够为 Mercurial 项目做出贡献。
通常,对于 GitHub 上的项目,我会从原始项目中分叉 GibHub 上的项目,然后使用两个不同的远程名称在本地获取这两个项目:
# Clone the initial repository and call the remote repository 'github-origin'
git clone -o github-origin git://github.com/orig_author/project.git
# Add the forked GitHub repo as an additional remote repo ('github-mine')
cd project
git remote add github-mine git://github.com/me/project.git
git fetch github-mine
当我使用 gitbranch -a 列出分支时,我得到这样的信息:
* master
remotes/github-mine/some_feature
remotes/github-mine/master
remotes/github-origin/HEAD -> github-origin/master
remotes/github-origin/some_feature
remotes/github-origin/master
我可以使用 git checkout -b new_feature 创建自己的本地分支,然后将其推回我的 GitHub 存储库,从而添加两个引用:
* my_feature
remotes/github-mine/my_feature
然后我可以联系原作者进行讨论此功能,提交拉取请求等等 在。 所有这些工作流程实际上完全独立于原作者的工作时间线。这使得讨论实验功能变得非常容易,而不会污染主项目的存储库。
如果原作者提交了更多更改,我可以跟上 git fetch github-orig 并可能相应地合并或重新调整我的本地更改。作为快速测试(假设当前分支是 my_feature
):
git fetch github-origin
git checkout -b temp
git rebase github-origin/master
此工作流程的一个要点是能够了解每个存储库的分支与我自己的分支相比的位置。特别是,重要的是要知道我的分支与同名的远程分支不同(即使在两个 GitHub 存储库之间,两个 master
分支也不需要相同,例如)。使用 gitk --all 可以很容易地看到这一切。
我不确定如何在 Mercurial 项目上(例如在 BitBucket 上)执行相同的操作。
这是我尝试做的,基于此命令等效表:
hg clone https://bitbucket.org/orig_author/project
# Edit .hg/hgrc and add 'bb-mine=https://bitbucket.org/.../project' to [paths]
# Apparently equivalent to git fetch.
hg pull bb-mine
这似乎工作,并且它会拉取远程提交(事实上,我已经在已经推送了我的分支之一的存储库上尝试过这一点)。我可以使用 hg Branch
看到所有分支,但没有指示它们来自哪里。 hg view
并没有真正显示任何内容。更重要的是,我的 tip
现在是我的最新提交,但我没有相当于我将拥有的 github-origin/master
标签(无论是在我自己提交之前或者在其他作者做出更多更改之后)。
我希望能够在将来的任何时间点执行 hg pull
(相当于 git fetch
),看看我的本地副本和本地副本之间有什么区别其他作者所做的新更改不一定会更改我的本地存储库或 BitBucket 存储库中的任何内容(至少在我解决了由于这些更改而导致的潜在冲突之前)。
除此之外,当我使用 Git 时,我还倾向于拥有自己的备份存储库(这是一个 SSH 服务器,我可以在其中推送所有分支,甚至是尚未发布的正在进行的工作) )。
我意识到 Mercurial 的分支方式与 Git 的方式不太一样。但是,Mercurial 是否有等效的工作流程,或者我只需要改变我的方法?如何查看我正在使用的每个存储库及其各自分支的最新情况(其中一些分支可能有共同点)?
I've been using Git for a while, and I'd like to convert my usual workflow to Mercurial. In particular, I'm interested in converting the workflow I would use to contribute to a Git project in order to be able to contribute to a Mercurial project.
Typically, for a project on GitHub, I would fork the project on GibHub from the original project, and then fetch both locally, with two different remote names:
# Clone the initial repository and call the remote repository 'github-origin'
git clone -o github-origin git://github.com/orig_author/project.git
# Add the forked GitHub repo as an additional remote repo ('github-mine')
cd project
git remote add github-mine git://github.com/me/project.git
git fetch github-mine
When I list the branches with git branch -a
, I get something like this:
* master
remotes/github-mine/some_feature
remotes/github-mine/master
remotes/github-origin/HEAD -> github-origin/master
remotes/github-origin/some_feature
remotes/github-origin/master
I can create my own local branches using git checkout -b new_feature
and then push it back to my GitHub repository, thus adding two references:
* my_feature
remotes/github-mine/my_feature
I can then contact the original author to discuss this feature, submit a pull request and so on.
All this workflow is actually quite independent from the original author's working time line. This makes it quite easy to discuss experimental features without poluting the main project's repository.
If the original author has commited more changes, I can keep up with git fetch github-orig
and possibly merge or rebase my local changes accordingly. As a quick test (assuming by current branch is my_feature
):
git fetch github-origin
git checkout -b temp
git rebase github-origin/master
An essential point of this workflow is to be able to know where each repository's branch is located compared to my own branches. In particular, it's important to know that my branches are not the same as the remote branches with the same name (even between the two GitHub repositories, the two master
branches don't need to be the same, for example). Seeing all this is something quite easy using gitk --all
.
I'm not sure how to do the same on a Mercurial project (e.g. on BitBucket).
Here is what I've tried to do, based on this Command Equivalence Table:
hg clone https://bitbucket.org/orig_author/project
# Edit .hg/hgrc and add 'bb-mine=https://bitbucket.org/.../project' to [paths]
# Apparently equivalent to git fetch.
hg pull bb-mine
This seems to work, and it pulls the remote commits (in fact, I've tried this on a repository where I've already pushed one of my branches). I can see all the branches using hg branches
, but no indication as to where they came from. hg view
doesn't really show anything. More importantly, my tip
is now the latest of my commits, but I don't have an equivalent of the github-origin/master
label that I would have (whether it's before my own commits or it's after if another author has made more changes).
I would like to be able to do an hg pull
(equivalent of git fetch
) at any point in time in the future to see what the differences between my local copy and the new changes made by the other author(s) are without necessarily changing anything in my local repository or in my BitBucket repository (at least until I've fixed potential conflicts due to those changes).
On top of this, I also tend to have my own backup
repository when I use Git (which is an SSH server where I can push all branches, even work in progress that is not meant to be published yet).
I realise that the Mercurial way of branching isn't quite the same as the Git way. However, is there an equivalent workflow for Mercurial, or will I just have to change my approach? How can I see where each of the repositories I'm using are up to with their respective branches (some of which they may have in common)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个很大的问题,所以我要挑几个要点。我认为您应该访问 IRC 频道 或 mailinglist 获取更多建议 - 我预测您的(进一步的)问题将具有讨论性质,最好在那里讨论。
不要过分强调
tip
标签。这是一个已弃用的概念,当您有多个分支时,它的意义越来越小。主要问题是它只是存储库中最新的变更集,因此当您拉取时它会从(命名)分支跳转到(命名)分支。我们更喜欢谈论default
以及其他命名的分支/书签,因为这些标识符以更受控制的方式移动。remotebranches 扩展 可能会帮助您获得更像 Git 的工作流程。
但一般来说,如果您想在 Mercurial 中使用类似 Git 的分支,则应该查看 书签。您使用
hgbranch
创建的命名分支与分支几乎没有相似之处你用 gitbranch 来创建(Git 缺乏 Mercurial 的命名分支概念)。使用
hg传入
和hg传出
来查看存储库之间的差异。这就是我通常如何查看需要从另一个克隆中拉取或推送到另一个克隆的内容。This is a huge question so I'm going to pick a couple of points. I think you should come to the IRC channel or the mailinglist for more advice — I predict that your (further) questions will be of a discussion kind of nature and it's much better to discuss things there.
Don't put much emphasis on the
tip
label. It's a deprecated concept that means less and less when you have multiple branches. The main problem is that it's just the most recent changeset in your repository and so it will jump from (named) branch to (named) branch when you pull. We prefer to talk aboutdefault
instead and other named branches/bookmarks since these identifiers move in more controlled ways.The remotebranches extension might help you get a more Git-like workflow here.
But in general, you should look into bookmarks if you want Git-like branches in Mercurial. The named branches you create with
hg branch
bears little resemblance to the branches you make withgit branch
(Git lacks the named branch concept of Mercurial).Use
hg incoming
andhg outgoing
to see the differences between repositories. This is how I normally see what needs to be pulled from or pushed to another clone.