Reputation: 24735
I use hg command to update a project from repository (mercurial repository).
hg pull
hg update
Problem is that from my last update, I modified some files for myself. Now the concern is updating from repository will overwrite my changes. How can I prevent that?
Upvotes: 6
Views: 3058
Reputation: 177901
hg pull
just retrieves new history, so would not affect uncommitted changes.
hg update
will update to the tip, but uncommitted changes are merged with the new parent.
You won't lose anything, although your merge tool may run if there are conflicts in the merge.
Note, however, that hg update -C
, will "cleanly" update to the tip, throwing out uncommitted modifications.
Create a simple two-changeset database. The first changeset (0) has two lines. The second changeset (1) has four lines.
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"
Update back to the first (earlier) changeset with two lines.
C:\example>hg update 0
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
C:\example>type file.txt
Line1
Line2
Make a change to the file by adding another line. hg st
shows that a change has been made, but it hasn't been committed with hg ci
yet.
C:\example>echo Line5 >>file.txt
C:\example>hg st
M file.txt
Now update to the newer changeset. For this case, the merge tool will open because "Line5" conflicts with "Line3" in this new changeset. I resolved the merge and saved.
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
Nothing lost!
Also check out Mercurial: The Definitive Guide and other Beginner's Guides.
Upvotes: 11