I'm looking for the equivalent of git fetch --all. I currently have three different remote paths configured for my repository. hg paths shows all three. How do I do hg pull --all to fetch the new change sets from all remote repositories?
I figured out how to do this with an alias. In your ~/.hgrc add:
[alias]
pullall = !$HG paths | cut -f 1 -d ' ' | xargs -n 1 $HG pull
Then you can run hg pullall to fetch all the remotes.
Related
1) How to get the list of files with their sizes of some commit through command line like this:
hg files --template "{name} {length}\n"
2) How to get the size of Mercurial through command line like this:
hg size my_directory
To my knowledge there's no straight forward way without any external utilities.
Make use of the appropriate OS utilities, answering both of your question at once (should work on *nix and OSX):
hg files -rXXX | xargs du -h
To report information about the size of a particular file as of a particular revision, you can use the pattern:
hg cat --rev REV FILE | wc -c
Generalizing this a bit, if REV is a specific revision of interest, we could obtain a listing of filenames and file sizes by writing:
hg files --rev $REV . |
while read -r f ; do
echo $f $(hg cat --rev $REV "$f" | wc -c)
done
I am importing one Mercurial repo into another, maintaining history. There are several bookmarked heads on the default branch, and I want those bookmarked heads to still be bookmarked in the new, merged repo. As far as I can tell, the two ways to do this is to either,
pull each bookmark individually
pull the entire thing and recreate the bookmarks by hand.
Extending the previous answer, here's how to push all branches using awk and the output of hg bookmarks in bash:
hg bookmarks | awk '{if (NF == 3) print $2; else print $1;}' | xargs -n 1 hg push -f -B
Unix:
hg push $(hg bookmarks -T "-B {bookmark} ")
Windows:
for /f "delims=" %A in ('hg bookmarks -T "-B {bookmark} "') do #hg push %A
PowerShell:
hg bookmarks -T "{bookmark}\n" | %{ Write-Host === Bookmark $_ === ; hg push -B $_ }
-B parameter can be used in push any amount of times. Full bookmarks list for repo you can get from hg bookmarks
In Mercurial it's possible to hg status only the modified/added/removed files by doing:
hg st -m
hg st -a
hg st -r
Is it possible to obtain the same behaviour for the diff command? From the man page, it seems not.
One option would be to use something like this:
hg status -mar --no-status | xargs hg diff
The --no-status flag insures that just the file name is sent to STDOUT.
Is there any Mercurial extension that can grep for "console.log" that might have been accidentally left over as debugging code?
Right now this is what I am doing:
1) hg out ssh://....
the above is to see what is the first committed revision in my local repo, say, the smallest revision is 3456
2) hg diff -r 3455 | grep "^+" | grep "console\.log"
The number 3455 is 3456 - 1. the first grep is to see newly added code. the second one is for console.log
This method can tell that I have "console.log" in the new code, but won't say what file it is in.
It sounds like you're in need of a commit hook. Try putting something like this into your .hg/hgrc (or ~/.hgrc if you want it global):
[hooks]
pretxncommit = sh -c 'if hg log -p -r $HG_NODE | grep -q '^\+.*console\.log' ; then exit 1; else exit 0; fi'
That will abort your commits if they would be adding a line that contains console.log. Your commit message will be saved in .hg/last-message.txt.
See http://hgbook.red-bean.com/read/handling-repository-events-with-hooks.html for more details.
Related to Mercurial: Merging one file between branches in one repo , I'm trying to perform a backout operation on a single file, even though that file was one of many participants in the revision being backed out.
HG being the changeset-oriented tool that it is, it doesn't want to operate on files.
Closest I could find was to use hg export to create a diff, hand-edit the diff, and then hg import to patch the file in reverse order.
..but then I hit this annoying situation where http://hgbook.red-bean.com/read/finding-and-fixing-mistakes.html claims that there is a --reverse option to hg patch when there is not.
So the closest thing I can think of is to generate a hand-edited patch as above, and then using vanilla patch -R to apply a reverse patch.
The hg backout command would seem to be useful here, but is actually a red herring.
There has GOT to be a better way, no?
You can do it using just the -I (include names matching the given patterns) argument for backout with a single line:
hg backout --merge -I thefiletorevert -m 'message' OFFENDINGREVISIONID
Example Script:
hg init testrepo
cd testrepo
echo -e "line1\n\nline3" > file1
echo -e "line1\n\nline3" > file2
hg commit -A -m 'changes to two files'
perl -pi -e 's/line1/line 1/' file1
perl -pi -e 's/line1/line 1/' file2
hg commit -m 'put spaces in line1'
perl -pi -e 's/line3/line 3/' file1
perl -pi -e 's/line3/line 3/' file2
hg commit -m 'put spaces in line3'
hg backout --merge -I file1 -m 'remove spaces from line1' 1
Sample output:
adding file1
adding file2
reverting file1
created new head
changeset 3:6d354f1ad4c5 backs out changeset 1:906bbeaca6a3
merging with changeset 3:6d354f1ad4c5
merging file1
0 files updated, 1 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)
Resulting File Contents:
file1:line1
file1:line 3
file2:line 1
file2:line 3
notice that file1 is missing it's space in line one after the backout of the middle changeset, and the verbose log shows only one file changed in the backout:
$ hg log -v -r tip
changeset: 3:6d354f1ad4c5
tag: tip
parent: 1:906bbeaca6a3
user: Ry4an Brase <ry4an#mini>
date: Mon Sep 14 12:17:23 2009 -0500
files: file1
description:
remove spaces from line1
Here's what I would do: Use a fresh clone of the tip revision.
hg backout --merge -r revision_where_the_change_happened
to merge the reversed changes into the working copy.
Now copy the file in question to your regular working copy and commit
hg commit -m "Reversed the changes to file.h made in revision bla"
and throw away the clone you created above.
This way, mercurial doesn't know that there is a connection between revision_where_the_change_happened and this commit. If you want mercurial to remember this, instead do a
hg revert {all files except the one in question}
after merging the backout commit into the working copy and before commiting. For the second way, you don't need to work on a clone, because you want to keep the backout commit.
I would guess that the choice of which way you use depends on how big a part of the changeset the particular file change was.
Use the revert command.
hg revert -r1 file
This should revert the contents of file to the version in revision 1.
You can then further edit it and commit as normal.