I am new to mercurial. So, please excuse my question if it sounds trivial. I am trying to figure out how to do a diff for multiple files. Here is my use case : I made changes to four files. However, I am only interested in seeing the changes I made in two of them (fileA and fileB). I thought something like this would work :
hg diff fileA fileB
But it does not.
You need either the --include(-I) or --exclude(-X) options such as:
hg diff -I fileA -I fileB
hg diff -X *.csv
Remember you can compare specific revisions too
hg diff -r 1234:tip -I fileA
Use hg help diff in the console to see all the options available or look here
Related
I'm sorry if it's odd question. I have a mercurial repository. Is it possible to get a diff of two different files from some revision by hg? For example, there is a revision
revision xxx
- file1
- file2
How I can get a diff of file1 and file2 by standard hg command or any extensions?
Thank you.
UPD
I would like something like this:
hg diff -r xxx file1 file2
Than I will have all changes between two files of same revision.
Initially I read your question differently, but your comment made clear that you are asking about the differences between two files of the same revision. That's nothing where the VCS has any stakes in.
You simply can use (on *nix systems) the diff command:
diff FILE1 FILE2
If you need the difference of the files at particular revisions, of course you can use mercurial before that in order to get to that:
hg update -rXXX
or even to see the difference of FILE1 at revision XXX compared to FILE2 at revision YYY (but beware, it changes the working dir content; make sure to undo the revert afterwards):
hg revert -rXXX FILE1
hg revert -rYYY FILE2
diff FILE1 FILE2
I have a mercurial repo with subrepos (also mercurial). Imagine the situation where I have changed the subrepos and the main repo. Now I want to see the changes between several commits including the changes in the subrepos.
Is it possible?
I use TortoiseHG and diffmerge. In diffmerege calling for visual diff from TortoiseHg, I can't see the changes in the subrepos between several commits.
In the command line you can do the following. Let us say you want to see all the changes of a subrepo named example between the changesets (in the main repo) c608f6017bd7 and 72d284a44170.
In the main repo
hg diff -rc608f6017bd7:72d284a44170 .hgsubstate | grep example
will return the changesets of the subrepo example, something like:
-001fc0acef220bcd42898ef3932dee8330ea64c0 example
+77f9db4d51c4b483607178aba91c872b0adedf1e example
Now you can see the logs and the diffs of the subrepo changes with:
cd example
hg log -r001fc0acef220bcd42898ef3932dee8330ea64c0:77f9db4d51c4b483607178aba91c872b0adedf1e
hg diff -r001fc0acef220bcd42898ef3932dee8330ea64c0:77f9db4d51c4b483607178aba91c872b0adedf1e
If you need it often, you can create a bash script named sublog like:
#!/bin/bash
r=$(hg diff -r$1:$2 .hgsubstate | grep $3 | cut -c 2-41 | tr '\n' ':' | sed 's/:$//'; echo '')
cd $3
hg log -r:$r
and use it like:
sublog c608f6017bd7 72d284a44170 example
I can only tell you how to achieve it on the command line - but that is readily available with tortoiseHG, too:
Most commands can be made aware of subrepositories by using the -S or --subrepos flag. As such, in order to see the diff between two changesets X and Y, including those on all subrepositories, do at the main repository:
hg diff -S -rX:Y
Mind, of course, that it will not show a diff in the subrepositories if there was no change of the sub-repository version(s) committed to the main one.
With the versions of TortoiseHg I've used (which doesn't include the last few releases), I haven't seen a way of doing what you're asking about. There are a few options though:
you can type commands directly in the output log window in TortoiseHg, so you can do hg diff -S -rX:Y there.
Archive the versions of the parent repo which you want to diff to some directories (hg archive --repository <path-to-repo> -r <rev> -S -t files -- <outputfolderpath>, or in TortoiseHg, right-click the changeset, select Export -> Archive). Then use diffmerge on the archive directories. This is a bit tedious (especially if you want to diff many changesets), but you will get a "deep" visual diff.
I want to see the difference between filea and fileb as of rev1234, because fileb appears to have been a fork-and-change-and-thereafter-run-two-versions-of-one-library, without a super informative commit message.
I tried hg diff -r 1234 filea fileb, but that just shows me two diffs:
that between filea as of rev1234 and its current version, and
that between fileb as of rev1234 and its current version
I want ONE diff, between filea as of rev1234 and fileb as of rev1234.
I understand that both files are present in r1234?
If r1234 is not your current working dir state, update your working directory to r1234 beforehand: hg update -r1234
Then you do not need any mercurial command but the normal diff command:
diff fileA fileB. When you're done, hg up again to return to normal.
It's roundabout, but you can create a directory, export just those two files from that revision, and then compare them:
mkdir tempdiff
hg archive -r 1234 -I filea -I fileb tempdiff/
diff tempdiff/filea tempdiff/fileb
rm -r tempdiff
A one-command method would be nice, though.
In Mercurial, I can see my current (uncommitted) changes by running
$ hg diff
Fine. But after commit, I sometimes want to see this diff again (i.e., the diff of the last changeset). I know I can achieve this by
$ hg log -l 1
changeset: 1234
tag ...
$ hg diff -c 1234
I'm looking for a way to do this in one line.
Use hg diff -c tip, or hg tip -p (shorter, but works only for tip).
This will work until you pull something, since tip is an alias for the most recent revision to appear in the repo, either by local commit or
pull/push from remote repositories.
You can use relative revision numbers for the --change option:
hg diff -c -1
See https://stackoverflow.com/a/3547662/239247 for more info.
An alternative is to use: hg diff --rev -2:-1
This form has the advantage that it can be used with the status command (e.g. hg st --rev -2:-1), and using it makes it easy to remember what to do when one needs to determine differences between other revision pairs (e.g. hg diff --rev 0:tip).
The answer from Macke is quite helpful, but in my case I didn't want to diff tip.
Thankfully you can also just diff the currently selected comment:
hg diff -c .
We can see all the changesets and the files involved using
hg outgoing -v
but the filenames are all scattered in the list of changesets.
Is there a way to just see a list of all the files that will go out if hg push is issued?
First, create a file with this content:
changeset = "{files}"
file = "{file}\n"
Let's say you call it out-style.txt and put it in your home directory. Then you can give this command:
hg -q outgoing --style ~/out-style.txt | sort -u
A somewhat under-appreciated feature: hg status can show information about changes in file status between arbitrary changesets. This can be used to get a list of files changed between revisions X and Y:
hg status --rev X:Y
In this case, we can use hg outgoing, to find the first outgoing changeset X and then do
hg status --rev X:
to see the files changes since revision X. You can combine this into a single line in your shell:
hg status --rev $(hg outgoing -q --template '{node}' -l 1):
I usually use
hg outgoing -v | grep files
It makes the listing shorter, but doesnt sort. But thus far I havent been in a situation where I want to push so much (and at the same time check the files) that its been a problem.
[Edit]
To do what you want:
Use cut to remove the files: part
For changesets with more than one touched file, use tr to put them on separate lines
Finally sort the resulting output with sort
Like so:
hg outgoing -v |grep files: |cut -c 14- |tr ' ' '\n' |sort -u
You can put this in ~/outgoingfiles.sh or something to have it nice and ready.
I use Torgoise Hg, which is a shell extension that has a "synchronize" view allowing you to see outgoing files before you push them. It's convenient for commits as well, and other things.
A simple hg out will also solve this.
It will list all committed but yet to push checkins.