hg log not finding file even though it exists - command-line

I am not understanding why Mercurial sometimes cannot find file when it does a log command, but it always finds it when I do a status.
For example:
hg status --change "1111" "path\to\file" -- Returns path to file
hg log -r "1111" "path\to\file" -- Returns changeset
But, sometimes it fails with a different changeset:
hg status --change "2222" "path\to\file" -- Returns path to file
hg log -r "2222" "path\to\file" -- Returns nothing
How can this be? If the file exists proven through the use of a status command, how can I not retrieve the changeset through log on some changesets?

Hidden in the documentation it seems like this solved my issue:
For performance reasons, 'hg log FILE' may omit duplicate changes made
on branches and will not show removals or mode changes. To see all
such changes, use the --removed switch.
Seems a little ridiculous that you have to specify this, especially when you already explicitly state the file.

Related

Find the list of file changes since last commit using mercurial

I am working on a project and I have to find the number of files added, deleted and modified since the last commit in mercurial hg.
hg status gives us the list of files which are modified, deleted and unknown. So using hg status is there any way i can get a count of all files added, deleted and modified?
Each file added, modified or deleted is listed on a line by itself, so you can count the lines for each. For instance, on Unix-like systems with the wc command:
hg status --modified | wc -l
Since the last commit it's always 0.
Describe your business-task in business-words

Reverse "hg update --clean"

Is the command described in the title reversible?
I tried searching the log (with hg log) and stripping the corresponding changeset, but no log was issued for this command.
Is the command described in the title reversible?
no, if you --clean, you'll lose all changes in working directory
I tried searching the log ... but no log was issued for this command
hg up does not affect repository in any way, it's a pure workdir command

mercurial hg partial checkin

It is a very simple and stupid question,
I am working on 2 tasks and modified 2 sets of files in the code.
Now when I type 'hg ci', it checks in all the files. Can I remove certain files from the checkin i.e. do checking for only one task?
If I remove the files in the 'check in message' will they be removed from the checkin
Thanks for all the answers
This seems like a big flaw, My use case is very simple and general. Most of the time dev are working on various tasks , some are ready , some are not, bug fixes etc.
Now the only simple solution seems to be multiple local repos or clones
Use hg ci <files>... to commit only certain files in your working directory.
If you want to pick file by file you can use the record command. It ships with mercurial, but you have to turn it on if you want to use it by putting: record= in the [extensions] section of your ~/.hgrc.
It goes hunk by hunk, but you can answer for a whole file:
y - record this change
n - skip this change
s - skip remaining changes to this file
f - record remaining changes to this file
d - done, skip remaining changes and files
a - record all changes to all remaining files
q - quit, recording no changes
? - display help
I'll point out that if you're committing some files but not others it's certain that you've not run your test suite on the one change without the other, but maybe that doesn't apply in your case.
This isn't possible with mercurial out of the box. As have been suggested there are several ways of selecting what files you want to commit. To get this function via the commit message template, you would need an extension or a shell script wrapping the commit command. Here's one way to do that:
[alias]
ci = ! hg-partial-commit
hg-partial-commit:
#!/bin/sh
# partial commit
edit=$(mktemp ${TMPDIR:-/tmp}/$(basename $0).XXXXXXXXXXXX)
filelist=$(mktemp ${TMPDIR:-/tmp}/$(basename $0).XXXXXXXXXXXX)
logmessage=$(mktemp ${TMPDIR:-/tmp}/$(basename $0).XXXXXXXXXXXX)
cleanup="rm -f '$edit' '$filelist' '$logmessage'"
trap "$cleanup" 0 1 2 3 15
(
echo user: $(hg debugconfig ui.username)
echo branch: $(hg branch)
hg parents --template 'parent: {rev}:{node|short} {author} {date|isodate}\n'
echo
echo 'Enter commit message. Select files to commit by deleting lines:'
hg status 'set:not unknown()' | sed -e 's/^/#/'
) | sed -e 's/^/HG: /' >"$edit"
${VISUAL:-${EDITOR:-vi}} "$edit"
egrep -v '^HG:' "$edit" >"$logmessage"
egrep '^HG: #' "$edit" | cut -c8- >"$filelist"
hg commit -l "$logmessage" "listfile:$filelist"
$cleanup
The real problem here is the fact that you're doing changes related to different tasks jumbled together. Mercurial has a few ways you can keep things separate.
Task Branches
Suppose you've been working on a task and you've checked in a few times since you last pulled, but things aren't ready to share yet.
o----o----B----o----o----o
Here, B is the revision where you started your changes. What we do is (after making sure our current changes are checked in):
> hg update -r B
<do our work on the other task>
> hg commit
We've now created a new branch with the changes for this task separated from the changes for our original task.
o----o----B----o----o----o
\
----o
We can do this for as many different tasks as we want. The only problem is that sometimes remembering which branch is which can be awkward. This is where features like bookmarks come in useful. A bookmark is a tag which moves forward as commits are made so that it always points at the head of a branch.
Mercurial Queues
MQ adds the ability to work on changes incrementally and move between them by pushing and poping then off a stack (or "Queue" I guess). So if I had a set of uncommitted changes that I needed to split up I'd:
> hg qrecord taska
> hg qrecord taskb
> hg qrecord taskc
I'd use the record extension (or more likely the crecord extension) to select which parts of files I want to select.
If I needed to go back to taska and make some changes:
> hg qpop; hg qpop # pop two off the queue to go back to task a
<Do changes>
> hg qrefresh # update task a with the new changes
When I want to turn the queue into normal changesets:
> hg qpush or hg qpop # get the changes I want converted onto the queue
> hg qfinish -a # converts mq changes to normal changesets
There's other methods too, but that will do for now.
You will unavoidably have to either specify the files that you want to add or the files you want to leave out. If you have a lot of files, as you indicate above, the following steps will simplify the procedure (I'm assuming a UNIX-ish system here, Windows would be slightly different).
First, generate a list of changed files:
hg status -mard -n >/tmp/changedlist.txt
The -mard options will list all files that were modified, added, removed, or delated. The -n option will list them without the status prefix so that all you have is a raw list of files.
Second, edit /tmp/changedlist.txt with your favorite text editor so that it contains only the files you wish to commit.
Third, commit these files:
hg commit `cat /tmp/changedlist.txt`
You will be able to review the files to be committed before actually performing the commit.
Alternatively, you can add more files to a commit incrementally by using
`hg commit --amend file...`
Here, hg commit --amend will not create a new commit, but add the new files to the existing commit. So, you start out with committing just a couple of files, then incrementally adding more until you are done. This still requires you to type all of them in.
For yet another alternative, you can use Mercurial Queues to split a commit in more sophisticated ways, but that's a bit more of an advanced topic.

How can I list all files I created?

I would like to get a list of all files in the current revision that were initially created by me. Does anyone know how I can do this?
Here's another approach that's a bit more direct.
for f in `hg locate`; do hg log -r "first(follow('$f'))" --template "$f: {author}\n"; done
Translation:
for each file
follow its history to the beginning
print the filename and author
To simply get a list of files first introduced by Bob:
for f in `hg locate`; do hg log -r "first(follow('$f')) and author(bob)" --template "$f\n"; done
Here's how you could do it on unix or mac:
for therev in $(hg log --template '{rev}\n' --rev 'author("ry4an")') ; do
hg status --added --no-status --change $therev
done
I'm afraid I've no idea how you'd do it on developer-unfriendly OSes. That gets all files you ever added, so you'd need to compare with hg manifest if you wanted to remove files that aren't in the current tip revision.

Check what will be committed before actually committing

I'm in the process of learning Mercurial, and even though I installed TortoiseHG, I find myself turning more and more to the command line.
So often I would like to check what the result of a given hg command would be before I actually run it. Is there any equivalent to the -whatif switch known from PowerShell I can use, or how would you go about checking what would be committed using a given hg commit statement?
When you do commit your message editor will contain a list of files that will be committed in the ignored section. If you commit with hg -m "message" this won't work as the editor step is skipped:
HG: Enter commit message. Lines beginning with 'HG:' are removed.
HG: Leave message empty to abort commit.
HG: --
HG: user: User <user#user.land>
HG: branch 'default'
HG: changed myfile.yxy
You can use hg commit and hg rollback to undo the last commit if it contained a file that you did not want to commit. The rollback works as long as you did not hg push to another repository.
Status works with the same patterns as commit. You can use hg status some/path/* and then hg commit some/path/* only replacing the command to use.
Often the -n switch or --dry-run switch will show you what would have happened for a particular command. commit doesn't have an -n switch, but you could run hg diff to see the actual changes, or hg status to see what's going on with each file.