Git和Mercurial:Mercurial中的Git工作流程相当于什么?

时间:2012-04-24 17:07:22

标签: git mercurial

#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这样的分支是禁止的,特别是永久分支删除...

2 个答案:

答案 0 :(得分:9)

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

# 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。一旦你在第一次拉动或推动书签时应该更新它,而不需要明确提及它。

答案 1 :(得分:5)

除了使用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

你也可以为了朋友的缘故推送书签,但是...... meh。