8

一般问题。

我正在尝试在 mercurial 中使用书签而不是分支。原因是我不想在分支中有很多不必要的固定名称的永久物品。

当我使用单独的书签进行新功能开发并且我想将其推送到 out 存储库时,就会出现问题。好吧,如果创建“新远程头”, hg不允许我推送。我应该怎么做才能像创建一个新分支一样进行推送?

示例(重现问题的方法)。

Alice 创建存储库:

C:\TestHg>mkdir Alice
C:\TestHg>cd Alice
C:\TestHg\Alice>hg init
C:\TestHg\Alice>echo line1>>file.txt
C:\TestHg\Alice>hg addremove
adding file.txt
C:\TestHg\Alice>hg commit -m "Initial commit."

Bob 克隆 Alice 的存储库:

C:\TestHg\Alice>cd ..
C:\TestHg>hg clone Alice Bob
updating to branch default
1 files updated, 0 files merged, 0 files removed, 0 files unresolved

Alice 对项目的代码进行了一些更改:

C:\TestHg>cd Alice
C:\TestHg\Alice>echo line2 by Alice>>file.txt
C:\TestHg\Alice>hg commit -m "Alice continues her work on the project."

Bob 使用单独的书签开始他的 New Cool Feature 工作,以标识他独立的工作“分支”:

C:\TestHg\Alice>cd ..\Bob
C:\TestHg\Bob>hg bookmarks
no bookmarks set
C:\TestHg\Bob>hg bookmark NewCoolFeature
C:\TestHg\Bob>hg bookmarks
 * NewCoolFeature            0:792db6cfc262
C:\TestHg\Bob>echo line2 by Bob (as a part of New Cool Feature implementation)>>file.txt
C:\TestHg\Bob>hg commit -m "Bob starts his work on New Cool Feature"

Bob 尝试将他的更改推送到 Alice 的目录:

C:\TestHg\Bob>hg push -B NewCoolFeature
pushing to C:\TestHg\Alice
searching for changes
abort: push creates new remote head 38506e28a438!
(you should pull and merge or use push -f to force)

好的,首先 Bob 必须将 Alice 的更改拉到他自己的存储库中:

C:\TestHg\Bob>hg pull
pulling from C:\TestHg\Alice
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
(run 'hg heads' to see heads, 'hg merge' to merge)

好吧,现在 Bob 在他的存储库中有两个头,这很好。

C:\TestHg\Bob>hg glog
o  changeset:   2:66beef200ba4
|  tag:         tip
|  parent:      0:792db6cfc262
|  user:        Alice
|  date:        Sun May 20 13:10:04 2012 +0400
|  summary:     Alice continues her work on the project.
|
| @  changeset:   1:38506e28a438
|/   bookmark:    NewCoolFeature
|    user:        Bob
|    date:        Sun May 20 13:12:26 2012 +0400
|    summary:     Bob starts his work on New Cool Feature
|
o  changeset:   0:792db6cfc262
   user:        Alice
   date:        Sun May 20 13:08:39 2012 +0400
   summary:     Initial commit.

在尝试再推一次之后,Bob 被要求合并。Bob 不想进行合并,因为他在 New Cool Feature 上的工作结果还没有为合并做好准备。

C:\TestHg\Bob>hg push -B NewCoolFeature
pushing to C:\TestHg\Alice
searching for changes
abort: push creates new remote head 38506e28a438!
(did you forget to merge? use push -f to force)

示例相关问题。

Bob 应该怎么做才能将他的更改推送到 Alice 的 repo,就好像他的更改在一个单独的分支中一样?

更新

UPD1:在现实生活中,Alice 的 repo 被用作开发团队所有成员的中央同步点。

4

1 回答 1

10

他应该:

  • 不推。为什么他要在别人的机器上完成他未完成的更改?
  • 强迫它。有人问他是否忘记合并。他没有。他想要一个新的头脑,所以强迫它。

信息就在那里,因为通常很容易在没有意识到的情况下创建一个新的头部。然而有时它正是你想要的,所以有覆盖开关。

于 2012-05-20T11:41:58.533 回答