将从mercurial更新覆盖我的更改?

mah*_*ood 6 mercurial

我使用hg命令从存储库(mercurial存储库)更新项目.

hg pull
hg update
Run Code Online (Sandbox Code Playgroud)

问题是,从我上次更新,我为自己修改了一些文件.现在关注的是从存储库更新将覆盖我的更改.我怎么能防止这种情况?

Mar*_*nen 10

hg pull 只检索新的历史记录,因此不会影响未提交的更改.

hg update 将更新到提示,但未提交的更改将与新父项合并.

尽管如果合并中存在冲突,您的合并工具可能会运行,您不会丢失任何内容.

但请注意,hg update -C将"干净地"更新到提示,抛弃未提交的修改.

创建一个简单的双变集数据库.第一个变更集(0)有两行.第二个变更集(1)有四行.

C:\>md example
C:\>cd example
C:\example>hg init
C:\example>echo Line1 >file.txt
C:\example>echo Line2 >>file.txt
C:\example>hg ci -Am "first checkin"
adding file.txt
C:\example>echo Line3 >>file.txt
C:\example>echo Line4 >>file.txt
C:\example>hg ci -Am "2nd checkin"
Run Code Online (Sandbox Code Playgroud)

使用两行更新回第一个(早期)变更集.

C:\example>hg update 0
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
C:\example>type file.txt
Line1
Line2
Run Code Online (Sandbox Code Playgroud)

通过添加另一行来更改文件. hg st表明已经进行了更改,但尚未提交hg ci.

C:\example>echo Line5 >>file.txt
C:\example>hg st
M file.txt
Run Code Online (Sandbox Code Playgroud)

现在更新到更新的变更集.对于这种情况,合并工具将打开,因为"Line5"与此新变更集中的"Line3"冲突.我解决了合并并保存了.

C:\example>hg update
merging file.txt
0 files updated, 1 files merged, 0 files removed, 0 files unresolved
C:\example>type file.txt
Line1
Line2
Line3
Line4
Line5
Run Code Online (Sandbox Code Playgroud)

什么都没有丢失!

另请参阅Mercurial:The Definitive Guide和其他初学者指南.