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"))'
Related
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.
Folks, I need your help!
I tried to push my hg repository to bitbucket for the first time. It didn't work and I thought this was because the project is to huge. Therefore, I wanted to push only one single file.
Since I did "hg add *" before, I wanted to revoke this, and typed "hg remove *" and now it DELETED FILES ON MY COMPUTER. But not all of them, only some...
I need these files back, how do I do it? Please tell me they're not gone, please please please.
Thank you so much for your help!!
This is my command history:
518 hg commit commit_test.txt -m "first commit"
519 hg add commit_test.txt
520 hg commit -m "test"
521 ls -ll
522 ls -la
523 cd .hg/
524 ls
525 ls -la
526 pico hgrc
527 cd ..
528 hg status
529 hg add commit_test.txt~
530 hg add commit_test.txt
531 hg commit -m "blabla"
532 hg push
533 hg add commit_test.txt
534 hg commit -m "maaan"
535 hg status
536 hg remove *
537 hg status
538 hg commit -m "bla"
539 ls
540 hg add test.txt
541 hg commit -m "test"
542 hg push
543 hg revert
544 hg revert --all
545 history
546 hg add *
547 hg add -r *
548 hg help add
549 hg add -S *
550 cd gui_relabel/
551 hg add *
552 cd images/
553 hg add *
554 cd ..
555 hg revert all
556 hg revert *
557 history
Here is what hg log gives me:
$ hg log
changeset: 6:4726f671ae96
tag: tip
user: KG <...#gmail.com>
date: Wed Dec 04 12:21:30 2013 +0100
summary: test
changeset: 5:55b3158def38
user: KG <...#gmail.com>
date: Wed Dec 04 12:17:19 2013 +0100
summary: bla
changeset: 4:ae0dd836586d
user: KG <...#gmail.com>
date: Wed Dec 04 12:14:50 2013 +0100
summary: blabla
changeset: 3:0249fdc26fa7
user: KG <...#gmail.com>
date: Wed Dec 04 12:13:59 2013 +0100
summary: test
changeset: 2:40bdcf4d2104
user: KG <...#gmail.com>
date: Wed Dec 04 12:12:37 2013 +0100
summary: first commit test
changeset: 1:f9e20020ca1d
user: KG <...#gmail.com>
date: Sun Nov 10 14:54:46 2013 +0100
summary: first commit
changeset: 0:7a8edcee06ff
user: KG <...#gmail.com>
date: Mon Nov 04 20:36:41 2013 +0100
summary: blabla
Your files are not gone. Mercurial does not throw away data, that is one of the first rules of the system.
To explain what hg remove did to your files, let us look at the cases one by one. A file in your working copy can be in one out of a handful different states: it can be modified, added, removed, missing, unknown, ignored, or clean.
I've prepared a working copy that looks like this:
$ hg status --all
M a
A b
R c
! d
? e
I f
C g
The files a to g are in the seven states I mentioned above. We can now talk about what happens when you try to remove these files:
A modified file (a) is not removed:
$ hg remove a
not removing a: file is modified (use -f to force removal)
An added file (b) is also not removed:
$ hg remove b
not removing b: file has been marked for add (use forget to undo)
A removed file (c) is no longer present in the working copy, so nothing more happens.
A missing file (d) is no longer present in the working copy, so nothing more happens.
An untracked file (e) is not removed:
$ hg remove e
not removing e: file is untracked
An ignored file (f) is not removed (since it is not tracked):
$ hg remove f
not removing f: file is untracked
A clean file (g) is removed.
The only type of file that hg remove will actually remove from your working copy is a clean file. A clean file is already committed, so the content is safely stored in the repository. You can get it back with hg revert:
$ hg revert g
$ hg status --all
M a
A b
R c
! d
? e
I f
C g
The file g is back with the same content as it had before you removed it.
It looks like you could run
hg backout 5
You can read more about backout if you like
When using mercurial, when working on a large change, I will do several commits (as safe points, or share my progress with coworkers).
Whe I am done, I want to push my changes into the main repository. Before I do that, though, I will want to do a "hg pull -u && hg merge"to get changes that occured since my last pull, and review my changes.
Because I have several changesets, running hg diff on each of those is not a good solution.
I tried running hg diff -c"outgoing() and not merge()" to only show the diff for my outgoing changesets (without merge ones, as this tends to only add noise which I want to avoid).
However, it is still not ok for me, as mercurial seems to skip some information, and I do not understand on what basis. Please refer to the scenario below:
full scenario:
# clean working directory
rm -fr base clone
#prepare reference repo
mkdir base; cd base
hg init
touch 1.txt
echo " 1\n2" >>1.txt
hg add 1.txt
touch 2.txt
hg add 2.txt
hg commit -m"initial commit"
cd ..
hg clone base clone
cd base
#update ref repo.
echo "foo" >> 1.txt
hg commit -m"update file on remote repository"
#make changes locally
cd ../clone
echo "foo" >> 2.txt
hg commit -m "update initial file"
#now we are ready to push
hg pull -u && hg merge
hg commit -m"merge"
#actually...
sed -i -e 's/foo/bar/' 2.txt
hg commit -m"changed my mind"
hg out
changeset: 1:fce14ac089b2
date: Thu Nov 14 11:17:08 2013 +0100
summary: update initial file
changeset: 3:1967c50242c0
parent: 1:fce14ac089b2
parent: 2:2cdaf75afc6d
date: Thu Nov 14 11:17:10 2013 +0100
summary: merge
changeset: 4:120a0b8a0ede
tag: tip
date: Thu Nov 14 11:18:54 2013 +0100
summary: changed my mind
#try to display my changes
hg diff -c"outgoing() and not merge()"
--- a/2.txt Thu Nov 14 11:17:10 2013 +0100
+++ b/2.txt Thu Nov 14 11:18:54 2013 +0100
## -1,1 +1,1 ##
-foo
+bar
#only one change here!
#but
hg log -r"outgoing() and not merge()"
changeset: 1:fce14ac089b2
date: Thu Nov 14 11:17:08 2013 +0100
summary: update initial file
changeset: 4:120a0b8a0ede
tag: tip
date: Thu Nov 14 11:18:54 2013 +0100
summary: changed my mind
#is ok
So, could anyone please explain to me why mercurial skips changeset fce14ac089b2 entirely? What I expect is a consolidated output, i.e something like:
--- a/2.txt
+++ b/2.txt
## -1,1 +1,1 ##
+bar
Thanks a lot in advance.
I think the problem is a misunderstanding of what hg diff -c aka hg diff --change does. It takes a single revision id and shows you the change made by that one revision relative to its left parent.
You're calling:
hg diff -c"outgoing() and not merge()"
which yields multiple revisions (it's a revision set), but only one of them is being used. You're essentially seeing the output of:
hg diff --change 120a0b8a0ede
If what you're trying to do is see all of your outgoing changes lumped together in one diff you don't want --change/-c.
If you think about it the revset outgoing() could contain many changeset from many branches so smooshing them all into one diff isn't necessarily possible at all.
If the view you're trying to get is "how does the most recent head on branch default locally compare to the most recent head on default remotely" you need to know the node id of the most recent head on default, and then locally you'd just run:
hg diff node_id_of_most_recent_head_on_default_at_remote_site
This isn't guaranteed, as I expect that there's some way to have a change graph where the last public ancestor isn't the change-set you're after, but...
> hg diff -r "last(ancestors(.) and public())"
diff -r 5579be654db4 2.txt
--- a/2.txt Sat Nov 16 11:03:06 2013 +0000
+++ b/2.txt Sat Nov 16 11:29:34 2013 +0000
## -0,0 +1,1 ##
+bar
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
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