How to get rid of older mercurial heads? - mercurial

Hi I hope you can from my i/o tell how to proceed to merge everything to the latest update without losing my changes:
$ hg merge
avbryter: grenen 'default' har 4 huvuden - sammanfoga med en specifik rev
(kör 'hg heads .' för att se huvuden)
ubuntu#ubuntu:/media/Lexar/montao$ hg heads
ändring: 192:e571b17295e9
märke: tip
förälder: 175:f50d4c4461e5
användare: tekniklas
datum: Sat Jan 08 04:45:07 2011 +0000
kortfattat: twitter support added
ändring: 191:9e419ce3e7e1
användare: tekniklas
datum: Wed Mar 09 12:56:27 2011 +0000
kortfattat: adsense maps
ändring: 159:f8d974793b12
förälder: 157:ef1d955b9236
användare: tekniklas
datum: Sat Dec 18 17:05:45 2010 +0000
kortfattat: remove
ändring: 89:008a2ac46b4f
användare: tekniklas
datum: Sun Aug 01 07:10:40 2010 +0000
kortfattat: classifiedsmarket/market/market_ad_preview.html
ubuntu#ubuntu:/media/Lexar/montao$
The latest version is good and I want to "lose" the older heads.
UPDATE. After proceeding with the tip this is the latest output from hg heads:
$ LC_ALL=C hg heads
changeset: 195:fa7d0ec3760d
tag: tip
user: tekniklas
date: Fri Mar 11 06:04:17 2011 +0000
summary: searchbox
changeset: 192:e571b17295e9
parent: 175:f50d4c4461e5
user: tekniklas
date: Sat Jan 08 04:45:07 2011 +0000
summary: twitter support added
changeset: 159:f8d974793b12
parent: 157:ef1d955b9236
user: tekniklas
date: Sat Dec 18 17:05:45 2010 +0000
summary: remove
changeset: 89:008a2ac46b4f
user: tekniklas
date: Sun Aug 01 07:10:40 2010 +0000
summary: classifiedsmarket/market/market_ad_preview.html
EDIT, current issue status is:
$ LC_ALL=C hg heads
changeset: 195:fa7d0ec3760d
tag: tip
user: tekniklas
date: Fri Mar 11 06:04:17 2011 +0000
summary: searchbox
changeset: 192:e571b17295e9
parent: 175:f50d4c4461e5
user: tekniklas
date: Sat Jan 08 04:45:07 2011 +0000
summary: twitter support added
changeset: 159:f8d974793b12
parent: 157:ef1d955b9236
user: tekniklas
date: Sat Dec 18 17:05:45 2010 +0000
summary: remove
changeset: 89:008a2ac46b4f
user: tekniklas
date: Sun Aug 01 07:10:40 2010 +0000
summary: classifiedsmarket/market/market_ad_preview.html
ubuntu#ubuntu:/media/Lexar/montao$ LC_ALL=C hg --config ui.merge=internal:local merge 195
abort: merging with a working directory ancestor has no effect

Mercurial is about building a permanent history of your work, so none of its normal usage modes include "getting rid" of old heads.
The most Mercurial-like way to do this is to merge that head in selecting nothing from it.
hg update tip
hg --config ui.merge=internal:local merge 191 # keep my files
Found here.
That will eliminate that head, selecting nothing from it.
Other options that actually remove it from history include just doing:
hg clone -r tip myrepo mynewrepo
Which gets you a new clone that has only your newest head and its ancestors (not its sibling heads) which you can replace your old repo with if you like the result.
That's generally inferior if you buy into the keep-everything-forever model (I do) and doesn't work at all if other people already have clones fo your repo.

Nowadays you can close your branches (anonymous or not) with:
hg commit --close-branch -m "Closing branch."
You need to be in the branch you want to close before doing it.
I think that closing branches is better than merging it discarding changes because have a better meaning. When closing you said "This changes aren't useful any more", when merging you said "I like the changes but they are already included manually" (but maybe is what you wanted).
You can see this related question Mercurial: beheading a head or this one if you don't want/can't update Can you close a Mercurial branch without updating to it first?.

You can close your old branches. See article from official wiki.

Try to merge with lastest remote head and then push your commit
hg merge
hg commit -m 'merge'
hg push

Related

Mecurial hg push error

I'm new to Mercurial and I was hoping that you guys could help. I made and committed some changes on the default and dev branch on my local system. When I ran the "hg push" command, I got the following error. Do you know what I have to do to fix it? Thank you.
searching for changes
abort: push creates new remote head 6a3192edc4aa!
(merge or see "hg help push" for details about pushing new heads)
==========
Output of hg log:
changeset: 6583:6a3192edc4aa
tag: tip
parent: 6581:049cddc21e42
parent: 6582:ae83c2445264
user: user1
date: Thu Aug 14 15:35:08 2014 -0400
summary: Merged with dev.
changeset: 6582:ae83c2445264
branch: dev
parent: 6579:dd7c0641e5cf
parent: 6581:049cddc21e42
user: user1
date: Thu Aug 14 09:53:09 2014 -0400
summary: Merged with default.
changeset: 6581:049cddc21e42
parent: 6577:df050be5e368
user: deploy
date: Fri Aug 08 21:07:14 2014 +0000
summary: Added tag 0.3.343 for changeset df050be5e368
changeset: 6580:f28967065103
parent: 6577:df050be5e368
user: user1
date: Thu Aug 14 09:27:44 2014 -0400
summary: Fixed a timeout bug.
changeset: 6579:dd7c0641e5cf
branch: dev
user: user1
date: Wed Aug 13 09:29:58 2014 -0400
summary: Fixed a few typos.
Changesets 6580 and 6583 are both on default branch, but are both heads. Issue a hg merge and you should be good to push.

Mecurial trying to merge file with identical DAGs

I have two repositories A and B.
I have pulled B into A.
For a given file on A hg log returns
changeset: 40967:d7f84148b444
parent: 40966:afbd3f7ddeea
parent: 40730:8658f8a70bd5
user: anon
date: Tue Nov 05 11:52:13 2013 +0000
summary: merge from B
changeset: 40894:7f667abe8948
user: anon
date: Wed Oct 16 11:53:13 2013 +0100
summary: Refactored some code
and on B hg log return
changeset: 40570:d7f84148b444
parent: 40402:afbd3f7ddeea
parent: 40569:8658f8a70bd5
user: anon
date: Tue Nov 05 11:52:13 2013 +0000
summary: merge from B
changeset: 39676:7f667abe8948
user: anon
date: Wed Oct 16 11:53:13 2013 +0100
summary: Refactored some code
The two graphs appear identical and there are no commits in A for the file that aren't in B and vice versa.
However merging the two heads in A requires a conflict to be resolved for this file.
I guess I'm missing something. What cases could cause Mercurial to think it needs to merge these two graphs?
Is there someway I can determine why Mercurial is trying to merge the file?

How to get previous changeset id of a specific file

I would like to get the previous revision for a specific file, no matter if it was changed in the tip or not.
For example, I have a repo that has a tip at changeset 226
$:~/sandbox$ hg log -r -3::.
changeset: 224:591c7a48b15f
user: blah <blah.com>
date: Tue May 28 09:07:25 2013 -0700
summary: TEST: test
changeset: 225:8c3689dedfa8
user: blah <blah.com>
date: Tue May 28 09:07:53 2013 -0700
summary: TEST: test2
changeset: 226:88f5ee46f99b
tag: tip
user: blah <blah.com>
date: Tue May 28 09:42:46 2013 -0700
summary: TEST:test
Inside that repo is a file called doit that was changed a while ago, at changeset 158:
$:~/projects/sandbox$ hg log doit
changeset: 158:8536d2b52f24
user: blah <blah.com>
date: Thu May 03 18:56:50 2012 -0700
summary: TEST: clean up buiild
changeset: 121:82313616d631
user: blah <blah.com>
date: Wed Apr 06 14:04:55 2011 -0700
summary: scr3: created program to test UI tests in Hudson
changeset: 116:c668d2a9c2b2
user: blah <blah.com>
date: Tue Feb 15 11:31:31 2011 -0800
summary: TEST: add another line
changeset: 115:9affabd80774
user: blah <blah.com>
date: Tue Feb 15 11:21:01 2011 -0800
summary: TEST: modify doit
changeset: 114:4097920e7edb
user: blah <blah.com>
date: Tue Feb 15 11:18:58 2011 -0800
summary: TEST: add doit
And I can dump the contents of the file using hg cat:
$:~/projects/sandbox$ hg cat -r 158 doit
#! /bin/sh
echo doit for the sandbox hudson test job...
echo add another line out
echo add yet another line...
#ant clean build
So far so good. The question is how do I specify the previous revision of the file (doit) without explicitly specifying "158". (I'd have to search the hg log output for it for example).
I've tried:
hg log -r -2 doit
hg log -r "ancestor(.)" doit
hg log -r "ancestor(file(doit))"
hg log -r "limit(file(doit))"
hg log -r "limit(file(doit)~0)"
(etc.)
I finally tried this one which seems to work:
$:~/sandbox$ hg log -r "last(file(doit))"
changeset: 158:8536d2b52f24
But when I tried it against another repo and file:
$:~/projects/otherrepo$ hg log -r "last(file(file-version))"
hg: parse error: file requires a pattern
It seems the dash "-" is causing a syntax issue. I tried escaping it:
$:~/projects/otherrepo$ hg log -r "last(file(uic\-version))"
hg: parse error at 13: syntax error
Any ideas on what to try next?
You can use different type of escaping:
hg log -r 'last(file("uic-version"))'

time for hg log --date

I generate hg logs for some repositories (on the remote server where all local repos push their changes to) using this command:
hg log -R "path-to-repo" -b somebranch --date "$YESTERDAY to $TODAY"
where :
YESTERDAY=$(date +%Y-%m-%d -d "yesterday")
TODAY=$(date +%Y-%m-%d)
As an example this could be:
hg log -R "path-to-repo" -b somebranch --date "2012-11-27 to 2012-11-28"
But at what time: hour:minutes:seconds does the generated log start when specifying --date? End would be the time when the command is executed.
The reason I ask is that the log was empty when I ran the above at 10:00 but when I ran it 11:10 it found changes.
You forgot about local timezone: date without TZ for mercurial is some predefined timezone (probably GMT)
BTW, "from yesterday" (without TZ-related headache) for hg log is static line --date "-1"
Example of log, when committer isn't from my local TZ
hg log --date "2012-11-04" --template "{date|date}\n"
Sat Nov 03 22:36:13 2012 -0400
Sat Nov 03 22:22:43 2012 -0400
Sat Nov 03 19:25:13 2012 -0400
Sat Nov 03 19:20:52 2012 -0400
Sat Nov 03 19:20:39 2012 -0400
Sat Nov 03 19:14:17 2012 -0400
Sat Nov 03 19:12:08 2012 -0400
Sat Nov 03 19:11:50 2012 -0400

Is it possible to (re)connect hgsubversion to a manually constructed repository?

I am working with a repository whose root has moved around some in its history (started at trunk/, moved to subproject/trunk). Right now I can either use hgsubversion to work with all the history up to the point when it moved to subproject/trunk (see https://bitbucket.org/durin42/hgsubversion/issue/135/move-tracking), or I can use hg convert or rebase to splice together the histories into one cohesive repository.
After splicing and calling hg svn rebuildmeta, hgsubversion is all confused. New revisions in the svn repository are pulled into a branch called "../".
Basically, I'm wondering if it's possible to tell hgsubversion to use a certain svn revision as its reference point, only attempting to sync up the histories from that point forward?
Here is a small test illustrating the issue (sorry for the DOS commands)
C:\hgtest>svnadmin create svnrepo
C:\hgtest>svn co file:///C:/hgtest/svnrepo svncheckout
Checked out revision 0.
C:\hgtest>cd svncheckout
C:\hgtest\svncheckout>mkdir trunk/
The syntax of the command is incorrect.
C:\hgtest\svncheckout>svn mkdir trunk
A trunk
C:\hgtest\svncheckout>cd trunk
C:\hgtest\svncheckout\trunk>echo "Test file version 1" > testfile.txt
C:\hgtest\svncheckout\trunk>cd ..
C:\hgtest\svncheckout>svn add trunk\testfile.txt
A trunk\testfile.txt
C:\hgtest\svncheckout>svn ci -m "Original version in trunk configuration"
Adding trunk
Adding trunk\testfile.txt
Transmitting file data .
Committed revision 1.
C:\hgtest\svncheckout>svn mkdir subproject
A subproject
C:\hgtest\svncheckout>svn mv trunk subproject
A subproject\trunk
D trunk
D trunk\testfile.txt
C:\hgtest\svncheckout>svn ci -m "Moved trunk to subproject/trunk"
Adding subproject
Adding subproject\trunk
Deleting trunk
Committed revision 2.
C:\hgtest\svncheckout>echo ". Adding some text to distinguish the subproject/trunk version of this file" >> subproject\trunk\testfile.txt
C:\hgtest\svncheckout>svn ci -m "Final version of testfile.txt"
Sending subproject\trunk\testfile.txt
Transmitting file data .
Committed revision 3.
C:\hgtest\svncheckout>svn log subproject\trunk\testfile.txt
------------------------------------------------------------------------
r3 | kmahan | 2012-02-17 09:18:23 -0800 (Fri, 17 Feb 2012) | 1 line
Final version of testfile.txt
------------------------------------------------------------------------
r2 | kmahan | 2012-02-17 09:17:40 -0800 (Fri, 17 Feb 2012) | 1 line
Moved trunk to subproject/trunk
------------------------------------------------------------------------
r1 | kmahan | 2012-02-17 09:14:46 -0800 (Fri, 17 Feb 2012) | 1 line
Original version in trunk configuration
------------------------------------------------------------------------
C:\hgtest>hg clone svn://localhost:22222/subproject/trunk hgrepo
[r2] kmahan: Moved trunk to subproject/trunk
[r3] kmahan: Final version of testfile.txt
pulled 2 revisions
updating to branch default
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
C:\hgtest>cd hgrepo
C:\hgtest\hgrepo>dir
Volume in drive C is OSDisk
Volume Serial Number is 74C7-4865
Directory of C:\hgtest\hgrepo
02/17/2012 09:30 AM <DIR> .
02/17/2012 09:30 AM <DIR> ..
02/17/2012 09:30 AM <DIR> .hg
02/17/2012 09:30 AM 104 testfile.txt
1 File(s) 104 bytes
3 Dir(s) 1,705,932,423,168 bytes free
C:\hgtest\hgrepo>hg log --follow testfile.txt
changeset: 1:eae92a250a90
tag: tip
user: kmahan#b3f284a4-0405-ad4c-b974-dac5aa90a095
date: Fri Feb 17 17:18:23 2012 +0000
summary: Final version of testfile.txt
changeset: 0:10c6ad198001
user: kmahan#b3f284a4-0405-ad4c-b974-dac5aa90a095
date: Fri Feb 17 17:17:40 2012 +0000
summary: Moved trunk to subproject/trunk
C:\hgtest>hg clone svn://localhost:22222/trunk -r 1 original-location
[r1] kmahan: Original version in trunk configuration
pulled 1 revisions
updating to branch default
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
C:\hgtest>cd hgrepo
C:\hgtest\hgrepo>hg pull -f ..\original-location
pulling from ..\original-location
searching for changes
warning: repository is unrelated
requesting all changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 0 changes to 1 files (+1 heads)
(run 'hg heads' to see heads, 'hg merge' to merge)
C:\hgtest\hgrepo>hg log
changeset: 2:f968692b6301
tag: tip
parent: -1:000000000000
user: kmahan#b3f284a4-0405-ad4c-b974-dac5aa90a095
date: Fri Feb 17 17:14:46 2012 +0000
summary: Original version in trunk configuration
changeset: 1:eae92a250a90
user: kmahan#b3f284a4-0405-ad4c-b974-dac5aa90a095
date: Fri Feb 17 17:18:23 2012 +0000
summary: Final version of testfile.txt
changeset: 0:10c6ad198001
user: kmahan#b3f284a4-0405-ad4c-b974-dac5aa90a095
date: Fri Feb 17 17:17:40 2012 +0000
summary: Moved trunk to subproject/trunk
C:\hgtest\hgrepo>hg rebase -s 0 -d 2
saved backup bundle to C:\hgtest\hgrepo\.hg\strip-backup\10c6ad198001-backup.hg
C:\hgtest\hgrepo>hg log
changeset: 1:ee10af28394f
tag: tip
user: kmahan#b3f284a4-0405-ad4c-b974-dac5aa90a095
date: Fri Feb 17 17:18:23 2012 +0000
summary: Final version of testfile.txt
changeset: 0:f968692b6301
user: kmahan#b3f284a4-0405-ad4c-b974-dac5aa90a095
date: Fri Feb 17 17:14:46 2012 +0000
summary: Original version in trunk configuration
C:\hgtest\hgrepo>hg svn rebuildmeta
C:\hgtest\hgrepo>hg pull
pulling from svn://localhost:22222/subproject/trunk
[r2] kmahan: Moved trunk to subproject/trunk
Marked branch ../ as closed.
[r3] kmahan: Final version of testfile.txt
no changes found
C:\hgtest\hgrepo>echo "Here's some more text" >> testfile.txt
C:\hgtest\hgrepo>hg ci -m "Test commit from mercurial side"
C:\hgtest\hgrepo>hg glog
o changeset: 5:a0e38c8fcfaf
| branch: ../
| tag: tip
| user: kmahan#b3f284a4-0405-ad4c-b974-dac5aa90a095
| date: Fri Feb 17 17:43:38 2012 +0000
| summary: Added new text from the svn side
|
o changeset: 4:39fe2d8d743c
| branch: ../
| parent: 0:f968692b6301
| user: kmahan#b3f284a4-0405-ad4c-b974-dac5aa90a095
| date: Fri Feb 17 17:18:23 2012 +0000
| summary: Final version of testfile.txt
|
| o changeset: 3:4a494fcf85f1
|/ branch: ../
| parent: 0:f968692b6301
| user: kmahan#b3f284a4-0405-ad4c-b974-dac5aa90a095
| date: Fri Feb 17 17:17:40 2012 +0000
| summary: Moved trunk to subproject/trunk
|
| # changeset: 2:547ed469c516
| | user: Kyle Mahan <kmahan#redacted.com>
| | date: Fri Feb 17 09:33:07 2012 -0800
| | summary: Test commit from mercurial side
| |
| o changeset: 1:ee10af28394f
|/ user: kmahan#b3f284a4-0405-ad4c-b974-dac5aa90a095
| date: Fri Feb 17 17:18:23 2012 +0000
| summary: Final version of testfile.txt
|
o changeset: 0:f968692b6301
user: kmahan#b3f284a4-0405-ad4c-b974-dac5aa90a095
date: Fri Feb 17 17:14:46 2012 +0000
summary: Original version in trunk configuration
Yes, but it'll be a manual process. You'll need to find the high water mark revision for each branch and record it in the metadata files (the names of which escape me at the moment). At that point, things should mostly work.
Note: this is a theory. I have high confidence that it should work based on my memory of the code, but I've never tested it.
Basically, I'm wondering if it's possible to tell hgsubversion to use a certain svn revision as its reference point, only attempting to sync up the histories from that point forward?
If I understood you correctly, you wanted --startrev option for clone command. From hg help subversion
Sometimes, past repository history is of little or no interest, and
all one wants is to start from today and work forward. Using
"--startrev HEAD" causes the initial clone to only convert the latest
revision; later pulls will convert all subsequent revisions. Please
note that this only works for single-directory clones