Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update to the last version in mercurial after adding new files?

I've created a repository in the project's directory. I've added all the files and made some commits. Then I added new files to project and to repository. After that I returned to earlier version and now I can't update to last version. After hg update tip I'm getting this message:

abort: untracked file in working directory differs from file in requested
revision: '.DS_Store'

I'm new to mercurial. How can I fix this?

like image 868
Andrew Avatar asked Jan 17 '12 06:01

Andrew


People also ask

Why does mercurial prevent me from updating the working directory?

However, once they try to hg update the working directory to that changeset, or hg merge with that changeset, Mercurial will spot the conflict between the two file names that the filesystem would treat as the same, and forbid the update or merge from occurring.

What happens when you add a file in mercurial?

Once you add a file, Mercurial doesn't do anything with it immediately. Instead, it will take a snapshot of the file's state the next time you perform a commit. It will then continue to track the changes you make to the file every time you commit, until you remove the file.

How to tell mercurial about a rename after the fact?

As with the results of a hg copy, we must use the -C option to hg status to see that the added file is really being tracked by Mercurial as a copy of the original, now removed, file. As with hg remove and hg copy, you can tell Mercurial about a rename after the fact using the --after option.

How do I back out a change in mercurial?

Backing out a change means, that you tell Mercurial to create a commit which reverses the bad change. That way you don't get rid of the bad code in history, but you can remove it from new revisions. The basic commands don't rewrite history. If you want to do that, you need to activate some of the extensions which are shipped with mercurial.


1 Answers

It means that Mercurial is unsure about what to do. You have a file with content something in the working copy. The file is not version controlled, so Mercurial will normally leave it alone when you update. However, the revision you're updating to also has a file with the same name, and the content differs from the something you already have in the file.

You can get this problem if you do

$ hg init
$ echo "a file" > a
$ hg add a
$ hg commit -m "added a"
$ echo "b file" > b
$ hg add b
$ hg commit -m "added b"

You now have two revisions, the latest has files a and b. If you update back to the first revision and create a different file b, then you get trouble:

$ hg update 0
$ echo "other b file" > b
$ hg update
abort: untracked file in working directory differs from file in requested
revision: 'b'

The normal solution is to commit before updating. You should generally not update with a dirty working copy ("dirty" means that hg status isn't empty). Mercurial does support such updates, but you should only use them if you know what you're doing.

So to continue the example above we can either commit the new b and then merge:

$ hg add b
$ hg commit -m "added new b"
$ hg merge

This gives a conflict in b since the two versions contain b file and other b file, respectively. Resolve the conflict and commit:

$ hg commit -m "merged two bs"

An alternative is to delete the file from the working copy. That is what I'll do in your case: .DS_Store files should not be tracked in the first place. They store some folder information on Mac OS X and this is not part of your source code. So you do

$ rm .DS_Store
$ hg update

The update resurrected the .DS_Store file. You now want to tell Mercurial that it should stop tracking the file:

$ hg forget .DS_Store

and you also want to tell Mercurial to ignore such files from now on:

$ echo "syntax: glob" >> .hgignore
$ echo ".DS_Store" >> .hgignore
$ hg commit -m "removed .DS_Store file, ignored from now on"
like image 123
Martin Geisler Avatar answered Oct 23 '22 23:10

Martin Geisler