Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

will update from mercurial overwrite my changes?

Tags:

mercurial

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?

like image 262
mahmood Avatar asked Dec 03 '11 05:12

mahmood


People also ask

What does hg update do?

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).

What does hg revert do?

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.

How do I delete a Mercurial repository?

Once you decide that a file no longer belongs in your repository, use the hg remove command.


1 Answers

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.

Example

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.

like image 96
Mark Tolonen Avatar answered Sep 30 '22 11:09

Mark Tolonen