添加新文件后如何更新到 Mercurial 的最新版本?

发布于 2024-12-27 09:43:37 字数 284 浏览 2 评论 0原文

我已经在项目目录中创建了一个存储库。我已经添加了所有文件并进行了一些提交。然后我将新文件添加到项目和存储库中。之后我回到了早期版本,现在我无法更新到最新版本。在 hg update Tip 之后,我收到此消息:

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

我是 Mercurial 的新手。我该如何解决这个问题?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

知足的幸福 2025-01-03 09:43:37

这意味着 Mercurial 不确定要做什么。您的工作副本中有一个包含内容 something 的文件。该文件不受版本控制,因此 Mercurial 通常会在您更新时保留它。但是,您要更新的版本有一个同名的文件,并且内容不同于您已有的内容文件。

如果您这样做,您可能会遇到此问题。

$ 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"

您现在有两个修订版本,最新的版本包含文件 ab。如果您更新回第一个修订版本并创建不同的文件 b,那么您就会遇到麻烦:

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

正常的解决方案是在更新之前提交。您通常不应使用脏工作副本进行更新(“脏”意味着 hg status 不为空)。 Mercurial 确实支持此类更新,但只有当您知道自己在做什么时才应该使用它们。

因此,要继续上面的示例,我们可以提交新的 b 然后合并:

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

这会在 b 中产生冲突,因为两个版本都包含 b 文件 > 和其他 b 文件,分别。解决冲突并提交:

$ hg commit -m "merged two bs"

另一种方法是从工作副本中删除文件。 这就是我在您的情况下要做的: .DS_Store 文件首先不应被跟踪。它们在 Mac OS X 上存储一些文件夹信息,这不是源代码的一部分。所以你

$ rm .DS_Store
$ hg update

更新了 .DS_Store 文件。您现在想要告诉 Mercurial 它应该停止跟踪该文件:

$ hg forget .DS_Store

并且您还想告诉 Mercurial 从现在开始忽略此类文件:

$ echo "syntax: glob" >> .hgignore
$ echo ".DS_Store" >> .hgignore
$ hg commit -m "removed .DS_Store file, ignored from now on"

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"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文