What is the easiest way of obtaining the changeset version of a particular file in Mercurial? A similar thing that we did for svn was to run "svn --info" in the command line and then obtain the Revision number. Is there any similar approach for Mercurial?
The concept you're missing is that all files are all the same changeset. Unlike SVN you update your entire working dir, not just folders and files. So you want:
hg id
to get just the rev number and hash, or
hg parents
to get info about the comment your current working dir is at, or
hg summary
for detailed info about what checkout you're at.
Simplest is hg log -l1 path/to/file.
Related
I am using hg convert to convert a Git repo into Mercurial on a Mac running macOS Mojave.
I've looked at similar questions How to use hg convert properly and hg convert not actually converting? but they haven't provided a definitive answer.
The command I've entered is:
hg convert ./my-src-dir/ my-dest-dir
The output is as follows:
initializing destination my-dest-dir repository
scanning source...
sorting...
converting...
6918 commit comment.
6917 commit comment.
6916 commit comment.
6915 commit comment.
6914 commit comment.
6913 commit comment.
This continues until the most recent commit...
1 commit comment.
0 commit comment.
updating bookmarks
I'm new to Mercurial. I can't see any errors but the destination directory only contains a .hg folder.
The output of hg sum is:
parent: -1:000000000000 (no revision checked out)
branch: default
commit: (clean)
update: 6919 new changesets (update)
phases: 6919 draft
Am I using this command correctly? I'm expecting to see all my src files in the new folder.
The key is:
parent: -1:000000000000 (no revision checked out)
The conversion presumably did work but you haven't yet updated your working folder to any particular changeset. So it appears to be empty.
Not knowing what (if any) branches, bookmarks, etc. are in the repo I can't say exactly what you should update to. But let's say you just want the last revision in there, you could do:
$ cd my-dest-dir
$ hg up tip
to get to whatever it thinks the last one is.
I'm looking for a way to view all of a repository's branches and each file that has changed in that branch. I'm not interested in the file level changes as this report is for simple auditing.
Can this be done?
hg log -b <branchname> --template "{files} "
Plus some post-processing, because output will be like this
lang/UTF-8/serendipity_lang_ru.inc.php lang/UTF-8/serendipity_lang_ru.inc.php lang/UTF-8/serendipity_lang_ru.inc.php lang/UTF-8/serendipity_lang_ru.inc.php plugins/serendipity_event_assigncategories/UTF-8/lang_ru.inc.php plugins/serendipity_event_entryproperties/UTF-8/lang_ru.inc.php plugins/serendipity_event_freetag/UTF-8/lang_ru.inc.php plugins/serendipity_event_gravatar/UTF-8/lang_ru.inc.php plugins/serendipity_event_relatedlinks/UTF-8/lang_ru.inc.php plugins/serendipity_event_nl2br/UTF-8/lang_ru.inc.php plugins/serendipity_event_freetag/UTF-8/lang_ru.inc.php
Use hg status to get information about files that have changed between revisions. See the revset language for how to select the revisions.
If you want to see file changes between the first and last changesets on branch B:
$ hg status --rev "min(branch(B)):max(branch(B))"
You can even make an alias for this:
[alias]
audit = status --rev "min(branch($1)):max(branch($1))"
and then use hg audit B to get the same result.
I tried to update some files to old revision in many ways, but I haven't found yet.
(not permanently, just temporarily updating for testing)
For example, the following is OK in SVN.
svn up -r 100 foo.cpp
U foo.cpp
But in Mercurial, 'up' command doesn't permit file name argument.
Only is it possible to update entire source tree in Mercurial?
You'd have to use hg revert:
hg revert -r 100 foo.cpp
Note that this gives you local changes, as can be seen by running hg diff.
See hg help revert for more info.
This is fundamentally disallowed by Mercurial and other DVCSs. Both CVS and Subversion track which revision you have checked out on a per-file basis. You could have r1 of file x and r2 of file y. In a DVCs the entire repository is at a single version, which in Mercurial you can see with hg id.
As #Tom points out you can have modified files from different revisions, but if you want to see another revision without changes showing up you need to do the update in another clone (which given that local clones use hard links to be (a) instant and (b) space efficient) that's not much of a hassle.
We have a Mercurial repository converted from Subversion a while ago and have today noticed that there are files in the repository that have no history whatsoever.
One of the sympomts of this behaviour is that hg status reports the file as clean, while hg log reports no changesets for the same file:
> hg clone [repo]
> hg st -c FileWithMissingHistory.cs
C FileWithMissingHistory.cs
> hg blame FileWithMissingHistory.cs
FileWithMissingHistory.cs: no such file in rev [...]
> hg log FileWithMissingHistory.cs
> hg log FileWithMissingHistory.cs -f
abort: cannot follow nonexistent file: "FileWithMissingHistory.cs"
> hg log -v | grep FileWithMissingHistory.cs
[gives output, there arechangesets mentioning the file]
Obviously the filenames have been changed in the example. I've tried using hg verify, but this command reports that the repo is fine. Has anyone experienced this and is there anything we could do to bring the history "back to life"? Placing dummy history on the files in question would be acceptable, but suboptimal.
EDIT:
I've done some more investigation and noticed that "FileWithMissingHistory.cs" was renamed from another filename (hg copy + delete) in revision 238. If I do hg update -r238 and hg log on the file at this revision I do not get any history. Doing hg log on the original file reports the history as expected, so it seems that the history is somehow lost during copy (again, the file is renamed using hg copy, and the changeset clearly indicates that the file has been copied).
Sounds strange, actually impossible. What I would try to debug this issue is to update to different revisions and check at which revision the file appears in the working copy the first time. If you do this in a binary search fashion (similar to how the bisect extension works), you should find a revision which introduces the file after a few updates.
This does not solve the problem, but it may help in tracking down its source.
I've finally tracked down the cause of the effects mentioned above and it seems that this is caused by mixed casing issues. Some of the files are located in directories with lowercase names while others are located in the directories with equal names, only that the case is mixed (e.g. "directory/FileWithHistory.cs" and "DiReCtOrY/FileWithMissingHistory.cs"). On Windows, both files will be located in the same directory causing issues.
Mercurial newbie here, I have a simple question.
I deleted one of my files from Mercurial and I want to get it back. I used to do svn up in Subversion, but in Mercurial it doesn't work, I tried hg up, and it does nothing.
I tried hg up to a specific file, and surprisingly (to me..) it told me:
abort: unknown revision '74656d706c617465732f6c6f67696e2e68746d6c'!
I tried to specify a revision and it told me:
abort: please specify just one revision
Isn't there a simple way of doing what I want?
Use hg revert.
hg revert -r REV path/to/file
where REV is the revision of the repository that contains the file you want to recover. See hg help revert for details.