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?
Description. Update the repository's working directory to the specified changeset. If no changeset is specified, update to the tip of the current named branch and move the active bookmark (see hg help bookmarks). Update sets the working directory's parent revision to the specified changeset (see hg help parents).
hg revert changes the file content only and leaves the working copy parent revision alone. You typically use hg revert when you decide that you don't want to keep the uncommited changes you've made to a file in your working copy.
Once you decide that a file no longer belongs in your repository, use the hg remove command.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With