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

ger*_*lus 10 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
Run Code Online (Sandbox Code Playgroud)

各种博客来源(但它们已经相当古老)说,像mercurial这样的分支是不行的,特别是永久分支删除......

Pau*_*l S 10

我可能有一些错误,因为我可能误解了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
Run Code Online (Sandbox Code Playgroud)

有一些"心理模型"的差异,但我认为它非常接近.最大的一个是删除书签.您在本地删除它,然后推送它被删除.你用git做的反转顺序.

还有一个问题是你用什么来识别"主"头.如果服务器上已有书签(master例如调用),则第一行将成为第一行hg pull -B master,即第一行合并hg merge master和更新hg update -C master.一旦你第一次拉动书签,你应该更新它,而不需要明确提及它.

  • @PaulS:您现在不再需要启用书签扩展,因为它现在已成为Mercurial的核心功能. (3认同)
  • @gerasalus:不,就像Git分支一样,书签不是永久性的.命名分支是永久标签,它们没有Git等价物.`default`指的是默认的*named*branch.它与`master`不同. (2认同)

Lau*_*lst 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
Run Code Online (Sandbox Code Playgroud)

如果你真的想明确跟踪匿名头,你可以选择使用书签; 当你开始(之后hg update)时,使用以下方法标记当前变更集:

hg bookmark makeSomeBugs
Run Code Online (Sandbox Code Playgroud)

当您完成(之后hg merge)时,使用以下命令删除书签:

hg bookmark -d makeSomeBugs
Run Code Online (Sandbox Code Playgroud)

您也可以为了朋友的缘故推送书签,但是......嗯.

  • 不,你正在提交一个新的匿名分支,可选择带有书签.只要提交行发散,就会发生分支.如果你想在"default"名称以外的地方提交,那么你需要创建另一个*named*分支.你在这里遇到了一个文化障碍:使用匿名分支在Mercurial中很常见,而在Git中几乎不可能.命名分支是永久性的,需要提前设置; 如果要跟踪该匿名分支,请使用书签. (2认同)