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.
Related
Given a checkout of a Mercurial repository and a filename. How does one determine the last commit that changed that file? Unlike git, care must be taken with branches. The intended semantic here is to follow the history of the branch. Where branches fork from other branches, follow parent branches.
Non-solutions:
shows commits from unmerged branches
hg log -l 1 filename
empty output if the file remains unchanged after branch creation
hg log -l 1 -b . filename
Arguably, this question highlights misuse of branches and bookmarks should be used instead. However that may be, existing history necessiates taking branches into account.
The -f flag tells hg log to follow history of the current or selected changeset, so this should find the first change of a file without looking at changesets that aren't direct ancestors:
hg log -f -l 1 filename
I want a simple command to get the list of files which differ after pushing to a mercurial repository on a server,
that is the differences between the previous push and the current push.
On the server, I have a hook on the changegroup event which calls a bash script.
$HG_NODE is the revision for the first commit in the changegroup.
My attempts:
hg status --rev $HG_NODE::
Exclude changes made in the first commit
hg status --rev $HG_NODE^1::
Includes changes that affected the parent revision through others pushes.
hg log -v --rev $HG_NODE:: | grep ^files
Include committed then reverted changes, still has 'files:' and files are not one per line
hg status --rev $HG_NODE:: && hg status change --rev $HG_NODE
Does not give exactly what I want, rather the change between the parent to the first commit in the changegroup + the change between this one (instead of the two changesets merged)
hg status --rev some_tag ; hg tag --remove some_tag ; hg tag --local some_tag
(Have not tried, is it a good idea?) Uses a local tag to keep track of the head for the last push, updates it each time.
Also I want to only monitor the default branch, so I assume I will use something like --rev "revision and branch(default)" or the branch option for hg log.
As to why, I need to go through the changes to determine parameters for an automated build.
hg stat -r is to list the removed files. To get the list of files which differ, you should use hg st --rev as follows.
hg st -m --rev tip^:tip
I just cloned a repo from their remote.
I built the software, changed about 4 files, committed them locally and now want to create a patch that I can show them.
When I run :
hg diff -U8p abc efg pqr > patch_file
I don't see the changes I made. Does hg diff only compare the current files with the last committed files?
How do I get this to work?
To diff the working directory against a particular revision REV, use
hg diff -r REV
To compare two revisions against each other, use
hg diff -r REV1 -r REV2
To figure out which revisions to compare, examine the output of hg log. If you'll be doing this a lot and the base revision is fixed, give it a name (e.g., whatipulled) with
hg tag -r REV whatipulled
You can then specify whatipulled as the revision, instead of a numeric rev id (or a hash).
To export your diffs in a richer format, including commit comments etc., you can also use the following which is designed for this purpose:
hg export -r REV
There's also hg bundle -r REV, which produces a binary file with similar information.
But if you're sending changes back to the parent repo, the best method is to use hg push. It communicates your changesets directly to the parent; you don't even need to know which changesets need pushing. Of course, you must have the right to push to the parent repo.
hg push [ parent_repo_url ]
(If you pulled from it, mercurial should already know the path and you can leave it out).
If the parent repo is on bitbucket and you don't have pu, you can set up your own account on bitbucket, pull/push to that from your local repo, and then issue a "pull request" to the project repo, asking them to pull from you.
All of the above have options to control their behavior, which see.
From hg help diff
If only one revision is specified then that revision is compared to the working directory
In your diff for -r you must to use old tip (latest "not your" changeset) and update to tip (your latest changeset) before diffing.
If some binary data was modified in your changesets, don't forget to use -g option
hg up & hg diff -r <CSET> -g > some.patch
Improved diff for any active changeset and without hand-work for detecting base changeset (for linear history == in single branch)
hg diff -r "parent(min(outgoing()))" -r tip
By default, hg diff compares the currently checked out file with the last commit. You can change this by adding options:
-r REV compares the currently checked out files with a specific revision REV.
-c REV shows the changes made by revision REV
So in your case hg diff -c 123 ... would give you the diff for commit 123.
My guess is that hg outgoing is exactly what you want -- it compares what you've committed locally with what is at the default remote server and shows you a list of those changesets or with -p the commits.
That does, however, shows each changeset separately. If you want to see all the changes combined, you'd have to do hg diff -r HERE -r THERE or since -r HERE is a default, hg diff -r THERE
I see you've asked in a comment "How do I know what THERE is", where THERE is the last changeset remote has, and you can get that answer by doing hg outgoing. If hg outgoing shows it would send changesets 66, 67, and 68, then you want to do hg diff -r 65 to compare what's already there (65) with what's local (68).
I could get it either with
hg status --change $HG_NODE
or with
hg log -r $HG_NODE --style mycustomstyle
But I can't get HG_NODE in precommit hook. Is there any workaround?
If
hg status --change $HG_NODE
is what you want, I guess you could just use:
hg status
$HG_NODE is not available in precommit since the changeset was not created yet
You may use the pretxncommit instead (Run after a new changeset has been created in the local repository, but before the transaction completes that will make it permanent)
Note that since the changeset is already 'done', modifications made to sources by the hooks will not be applied in the current changeset.
I'm currently trying to update a source file with the current changeset while committing, but I didn't found a solution yet
There are two heads on my repository. I have five files that I've edited locally. The Bitbucket repo has 15 changed files that I haven't edited, but it also contains changed versions of the same 5 files.
I'd like to do the following:
1) If I've edited a file and the Bitbucket repo contains the same edited file, I'd like my changes to take preference.
2) If I haven't edited a file, I'd like to update to the latest version.
What sequence of commands in Mercurial will let me do this? Do I have to use an external program?
WITH LOCAL COMMITS
hg pull
hg update --rev ${my version}
hg merge --rev ${their version} --tool internal:local
See also hg help merge-tools
WITHOUT LOCAL COMMITS
hg status -qn gives you a list of files you have changed. Since it's only five files, I'd copy them away manually, then revert, pull, update and copy them back into place. On unix you could write a throw-away shell script, something that goes kinda' like this:
ls -l *.mine # check to see that there are none
for file in `hg status -qn`; do cp ${file} ${file}.mine; done
hg revert --all; hg pull; hg update
for file in *.mine; do cp ${file} ${file%.mine}; done
This is untested code. Run it at your own risk. Eat muffins and be happy.
just do
hg pull
hg merge
This will pull the latest changes from bitbucket and allow you to merge your local changes the way you want.
This is really a basic functionality, you should read some documentation about mercurial, for example HG Init like said in the comments.