Git 和 Mercurial:相当于 Mercurial 中的 Git 工作流


#lets get the latest
git pull
#lets switch to branch and do some work
git checkout -b makeSomeBugs
#do the work commit
git add .
git commit -am "introducing some bugs"
#push this for my lazy remote friend to see
git push origin makeSomeBugs
#uh .. changes on master
git pull origin master
#do some work..
git commit -am "introducing some more bugs"
git push origin makeSomeBugs
#lets switch back to master
git checkout master
git pull
#work is done, lets merge
git merge --no-ff makeSomeBugs
git push origin
#and remove the branch to never ever see it again
git push origin :makeSomeBugs
git branch -d makeSomeBugs

各种博客来源(但它们已经很老了)说,像这样在 mercurial 中分支是不行的,尤其是在永久删除分支的情况下......

我可能有一些错误,因为我可能误解了 git,但假设您使用的是最新版本的 Mercurial,或者如果没有,书签扩展已启用......

# lets get the latest
# git pull
hg pull
# lets switch to branch and do some work
# git checkout -b makeSomeBugs
hg bookmark makeSomeBugs
# do the work commit
# git add .
# git commit -am "introducing some bugs"
hg commit -m "introducing some bugs"
# push this for my lazy remote friend to see
# git push origin makeSomeBugs
hg push -B makeSomeBugs
# uh .. changes on master
# git pull origin master
hg pull
hg merge
# do some work..
# git commit -am "introducing some more bugs"
# git push origin makeSomeBugs
hg commit -m "introducing some more bugs"
hg push -B makeSomeBugs
# lets switch back to master
# git checkout master
# git pull
hg pull
hg update -C <name of master rev>
# work is done, lets merge
# git merge --no-ff makeSomeBugs
# git push origin
hg merge makeSomeBugs
hg push
# and remove the branch to never ever see it again
# (I assume you mean the label not the changesets)
# git push origin :makeSomeBugs
# git branch -d makeSomeBugs
hg bookmark -d makeSomeBugs
hg push -B makeSomeBugs

有一些"心智模型"的差异,但我认为它非常接近。最大的一个是当您删除书签时。您在本地删除它,然后推送它已被删除。与你对 git 所做的顺序相反。

还有一个问题是你用什么来识别"主"头。如果服务器上已经有一个书签(例如称为master),则第一行将变为 hg pull -B master ,第一个合并hg merge master和更新hg update -C master。第一次拉取书签后,任何后续拉取或推送都应更新它,而无需明确提及它。

它几乎是一样的,除了使用 Mercurial,您通常根本不会费心命名您的进度,而只是使用匿名分支。

我会让它沉入一会儿...

与 git 不同,如果没有与之关联的分支名称或书签,Mercurial 不会"忘记"变更集,因此无需命名它,然后删除它。在此之后,它看起来像一个非常标准的工作流程:

#lets get the latest
hg pull
#lets update to the latest and do some work
hg update
#do the work commit
hg commit -Am "introducing some bugs"
#serve this for my lazy remote friend to see
hg serve
#uh .. remote changes
hg pull
#do some work..
hg commit -Am "introducing some more bugs"
#lets pull in the latest
hg pull
#work is done, lets merge
hg merge
hg push

或者,如果您确实想要显式跟踪匿名头;当您开始(在hg update之后)时,可以使用以下方法标记当前变更集:

hg bookmark makeSomeBugs

完成后(hg merge后),使用以下方法删除书签:

hg bookmark -d makeSomeBugs

您也可以为了朋友而推送书签,但是...唉。

最新更新