9

So there was a new branch created where we made some breaking changes to the codebase.

Now we are going to merge, but before that I want to get a list of all the files that were changed in the branch.

How can I get a list of files? I tried:

hg status --change REV

But i'm not sure if that is what I want, since I want all files changed in this branch and not a specific revision in the branch.

BTW, how can I view the revision numbers?

Martin Geisler
  • 69,865
  • 23
  • 162
  • 224
codecompleting
  • 8,513
  • 13
  • 56
  • 95
  • 1
    Great, someone has found `hg status --change`! :-) People almost always use `hg diff` or `hg log -v` when they're searching for files changed between two revisions. I'm out of votes right now, but I'll upvote tomorrow! – Martin Geisler Jan 19 '12 at 16:11

5 Answers5

8

Try with

$ hg status --rev "branch('your-branch')"

to get the changes between the first and the last changeset on the branch (hg status will implicitly use min(branch('your-branch')) and max(branch('your-branch')) when you give it a range of revisions like this).

Since you'll be merging, you should really look at

$ hg status --rev default:your-branch

to see what is changed between the default branch and your-branch. This shows you the modifications done, and filters out any modifications done on the branch due to merges with default.

This is necessary in case your history looks like this:

your-branch:      x --- o --- o --- o --- o --- o --- y
                 /           /           /
default:  o --- a --- o --- b --- o --- c --- o --- o --- d

where you've already merged default into your branch a couple of times. Merging default into your branch is normal since you want to regularly integrate the latest stuff from that branch to avoid the branches drifting too far away from each other.

But if a new file was introduced on default and later merged up into B, then you don't really want to see that in the hg status output. You will see it if you do

$ hg status --rev a:y

since the file was not present in a, but is present in y. If you do

$ hg status --rev d:y

then you wont see the file in the output, assuming that it's present in both heads.


You write in a comment that you're working Kiln repository. They mean "clone" when they say "branch", but the above can still be adapted for your case. All changesets will be on the default named branch, but that's okay.

Run the following command in your local clone of the "branch" repository:

$ hg bookmark -r tip mybranch

This marks the current tip as the head of mybranch. Then pull all the changesets from the main repository:

$ hg pull https://you.kilnhg.com/Repo/public/Group/Main

You then mark the new tip as the tip of the main repository:

$ hg bookmark -r tip main

You can now run

$ hg status --rev main:mybranch

to see the changes between main and my-branch. If you want to see what you did on the branch itself, the use

$ hg status --rev "::mybranch - ::main"

The ::mybranch part will select changesets that are ancestors of mybranch — this is all your new work, plus old history from before you branched. We remove the old history with - ::main. In older versions of Mercurial, you would use hg log -r -r mybranch:0 -P main.

Martin Geisler
  • 69,865
  • 23
  • 162
  • 224
  • my branch name is like: `this-is-a-branch` do I put it in quotes? – codecompleting Jan 19 '12 at 16:23
  • Yes, quotes are mandatory when you have `-` in the branch name. – Martin Geisler Jan 19 '12 at 16:24
  • how do I know which revision number I branched from? hg log doesn't have paging, so it flies off my screen buffer! – codecompleting Jan 19 '12 at 16:25
  • strange, hg branch says my branches name is 'default' does this mean it was cloned and not branched? – codecompleting Jan 19 '12 at 16:29
  • 1
    Use `hg log -l 30`, `hg log | less`, or the [pager extension](http://mercurial.selenic.com/wiki/PagerExtension) to handle the log. See `hg branches` for the list of all branches. If there's only `default`, then you probably cloned your repo instead of making a [named branch](http://mercurial.selenic.com/wiki/NamedBranches). – Martin Geisler Jan 19 '12 at 16:42
  • if it was a branch, would hg parents in the branch folder point to the original trunk? – codecompleting Jan 19 '12 at 16:46
  • yes it seems it was cloned, not branched as I only see default. But Kiln does show it has a branch, but the command line hg branches just shows default on the trunk repo. – codecompleting Jan 19 '12 at 16:54
  • so I guess that handy command `g status --rev default:your-branch` can't be used now to help filter out what was merged from the other repo. – codecompleting Jan 19 '12 at 16:55
  • Added more help, this time for Kiln. – Martin Geisler Jan 19 '12 at 18:00
  • sorry little confused, did you outline what SHOULD have been done in order to track changes, or can I do this now? we didn't tag/bookmark when the clone occurred. – codecompleting Jan 19 '12 at 19:10
  • when I pull in the old "main", do I merge? – codecompleting Jan 19 '12 at 19:35
  • @codecompleting: you can delete old and outdated comments. and yes, the commands I give can be used now in your current situation. You ask if you need to merge — that's really a question you should answer, not me :) You pulled the changesets into your clone so that you can get a list of files changed. If you're happy with the changes, then merge and push back to the main repo. – Martin Geisler Jan 20 '12 at 10:09
0

I had to merge the default branch into my branch to get some fixes, now the commands above shows also files changed because of merges (this files changed after the merge again in the default branch).

Therefore, to get only the correct files I use something like this:

hg log --rev "branch('my-branch') and not merge()" --template '{files}\n' | sed -e 's/ /\n/g' | sort -u

if you have spaces in file names, you can do it this way:

hg log --rev "branch('my-branch') and not merge()" --template '{rev}\0' | xargs -0 -I @ hg status -n --change @ | sort -u

And to answer your last question, revisions can be shown this way:

hg log --rev "branch('my-branch') and not merge()" --template '{rev}\n'

TIP: I use a hg-alias for this:

[alias]
_lf = ! $HG log --rev "branch(\"$1\") and not merge()" --template '{rev}\0' | xargs -0 -I @ hg status -n --change @ | sort -u
Mayra Delgado
  • 403
  • 3
  • 13
0

With mercurial, if you want to get the list of all the files changed in your current branch (changes done of your changeset) you can use these commands: :

hg log --branch $(hg branch) --stat | grep '|' | awk -F\  '{printf ("%s\n", $1)}' | sort -u

Example result:

api/tests/test_my_app.py
docker/run.sh
api/my_app.py

Explanation of the commands:

hg log --branch $(hg branch) --stat

Show revision history of entire repository or files and output diffstat-style summary of changes

hg branch

Show the current branch name

grep '|'

Search for a text pattern, in this case, it is "|"

awk -F\  '{printf ("%s\n", $1)}'

Space separator denotes each field in a record and prints each one in a new line

sort -u

Sort all the printed lines and delete duplicates

Rafa M.
  • 31
  • 2
0

In cases like this, I prefer to do a test merge from a newly checked-out copy of the repo. This has the advantage that I can see how many conflicts the merge will produce, and I can keep the merge result because I did it in its own copy.

daniel kullmann
  • 12,359
  • 6
  • 48
  • 63
0

To view the revision numbers, enable the graphlog extension and run:

$ hg log -b your-branch -G

This gives you a nice ASCII graph. This can be handy to quickly look at the graph, but I recommend using TortoiseHg for a cross-platform log viewer:

TortoiseHg 2.0 workbench

Martin Geisler
  • 69,865
  • 23
  • 162
  • 224