Archive for the 'mercurial' Category

05
Sep
11

mercurial fold commits

Practical example of folding three commits into one. For this to work, commits should not have been pushed.


D:\test\hgt>hg init

D:\test\hgt>touch one

D:\test\hgt>hg add .

adding one

D:\test\hgt>hg commit -m one

D:\test\hgt>touch second

D:\test\hgt>hg add .

adding second

D:\test\hgt>hg commit -m second

D:\test\hgt>hg log

changeset:   1:6ac539119ec9
tag:         tip
user:        John
date:        Mon Sep 05 00:06:03 2011 +0300
summary:     second

changeset:   0:60aac1a7734b
user:        John
date:        Mon Sep 05 00:05:56 2011 +0300
summary:     one

D:\test\hgt>ls
one  second

D:\test\hgt>touch third

D:\test\hgt>hg add .

adding third

D:\test\hgt>hg commit -m third

D:\test\hgt>hg qimport -r0:tip
D:\test\hgt>hg qser

0.diff
1.diff
2.diff

D:\test\hgt>hg qpop -a

popping 2.diff
popping 1.diff
popping 0.diff
patch queue now empty

D:\test\hgt>hg qpush 0.diff

applying 0.diff
now at: 0.diff

D:\test\hgt>hg qfold 1.diff


D:\test\hgt>hg qfold 2.diff


D:\test\hgt>hg qser

0.diff

D:\test\hgt>hg qref -m "One,two and three"


D:\test\hgt>hg qfinish 0.diff


D:\test\hgt>hg log

changeset:   0:93524a39039d
tag:         tip
user:        John
date:        Mon Sep 05 00:05:56 2011 +0300
summary:     One,two and three

04
Sep
11

remove all files with a certain extension from a mercurial repo in one line


I wanted to remove all .gitkeep files from a generated rails app. To show them, run this:

hg locate .gitkeep

And to delete them, we make use of rm. Combining them, we get this:

hg locate .gitkeep | xargs hg rm

02
Sep
11

remove old/closed branches from mercurial


If for example you want to remove no longer used branches, the convert extension can help. You need to provide it with a branchmap, like this:


hg convert --branchmap=some_file.txt old_repo new_repo

And the contents of the some_file.txt should be like this:


no_longer_used_branch default

30
Aug
11

using winmerge as difftool for mercurial


Described here:


[extensions]
; must uncomment this line
extdiff =

[extdiff]
; i'm using winmerge unicode version
cmd.winmerge = C:\Program Files (x86)\WinMerge\WinMergeU.exe
; it explains winmerge command line parameters here: http://winmerge.org/docs/manual/CommandLine.html
opts.winmerge = /r /e /x /u /wl

23
Aug
11

convert git repo to mercurial


Enable the convert extension by adding this in the .hgrc:


[extensions]
convert=

Then:


hg convert --datesort git_repo location_of_new_hg_repo

20
Aug
11

work with git, push to mercurial repo

I would like to give credit for most of this information to Chris Adams’s article. Thank you Chris!

  1. Install git
  2. Install Mercurial
  3. Get hg-git from hg-git page
  4. NOTE: If you install TortoiseHG with Mercurial, you get dulwich for free. I don’t know if this applies for a regular Mercurial install as well ( I always get the package that contains TortoiseHG )
  5. Open the .hgrc file, and add this to it:

    
    [extensions]
    hggit=/path/to/extracted-hg-git/hggit
    bookmarks=
    [git]
    intree=1
    
    [bookmarks]
    track.current=True
    
  6. hg clone hgrepo
  7. Create a bookmark from the first revision of Mercurial’s default branch:
    
    hg book hg/default -r default
    
  8. Export it to git:
    hg gexport
  9. Create the git master branch:
    git branch --track master hg/default
  10. The git repository is a bare one, so, you should clone your repo elsewhere to work on it:
    git clone repo new_repo_location
  11. Work on new_repo_location, do commits, and then do a push so the changes get back to the Mercurial repo
  12. Go back to the original Mercurial repo, and import the git changes:
    hg gimport
  13. Push them via Mercurial

08
Aug
11

mercurial remove specific commit from history


hg init
touch a b c d
hg add .
hg commit -m a a
hg commit -m b b
hg commit -m c c
hg commit -m d d

Let’s say we want to remove the commit b:


hg qinit -c
hg qimport -r1:tip
hg qpop -a
hg qdele 1.diff
hg qpush 2.diff
hg qfold 3.diff
hg qref -m "new commit message"
hg qfinish -a




Blog Stats

  • 216,805 hits