background
I am writing to commemorate the recent move from Mercurial versioning to GitLab.
What is HG Mercurial
Mercurial is a cross-platform distributed version control software in the IT world, implemented primarily in the Python language. Mainly is the command line program operation, it also has the image. Because the software named Chinese translation is – mercury, in order to enter the command convenient, with the element named Hg to call the program as the key word.
One of the most popular hosting services on the Web today is bucket
wiki
As for me, I have used SVN, Git, and finally came into contact with HG. The command is like git, but not as complicated as git. If you say it is like SVN, you feel that this software is relatively young.
Basic operation
$hg help $hg help ## $hg init ##, $hg status ##, $hg paths ##, $hg branch ##, $hg log $hg init ##, $hg log $hg init ##, $hg status ##, $hg paths ##, $hg branch ##, $hg log
Content management
Cloning to local $# # from the remote warehouse hg clone ssh://[email protected]/repository # # $hg add new file "file - the name" # # after change $hg commit -m 'change description... '## Push changes to the branch to the remote repository $hg push -r "version_number" ## Pull from the remote repository $hg pull ## Merge contents pulled to the local remote repository with the local repository $hg fetch ## Undo changes to the current file $ $hg revert "file-name" ## Undoes the last commit and places the last commit in $hg rollback
HG ROLLBACK can only be rolled back once. If you commit twice and run ROLLBACK twice, you can only rollback the most recent one.
Branch management
$hg update "branch_name" $hg merge this branch into the current branch $hg push-b "branch_name" $hg push-b "branch_name"
This branching operation, the feel of SVN
The draft
HG draft management
## Save the current tracked changes to the draft, $hg shelve --name "draft_name" ## Show draft of current project $hg shelve --list ## Apply the changes saved in draft to current project $hg unshelve "draft_name"
analogy
git stash
To use this feature, you need to enable extended shelve
contrast
$hg diff $hg diff $hg diff $hg diff $hg diff $hg diff $hg diff $hg diff $hg diff $hg diff -r "ver1" -r "ver2"
Came to
## Copy this version of the commit record directly to it. If the command succeeds, a commit record will be generated on the current branch! $ hg graft -r "rev"
is
git cherry-pick
Import the patch
$hg import code.patch --no-commit $hg import code.patch --no-commit $hg import code.patch --no-commit
You can use this feature as a way to save drafts or to push edits to others offline
other
HG log view
## View the latest version $hg tip ## View the log with branch chart $hg log-g ## View the log with this commit $hg log-r "version_number"
HG uses self-incrementing natural numbers and hash characters to manage the version number. It combines SVN and Git version numbers in one
## View the previous version of the commit log $hg parent
configuration
The global configuration file is in ~/.hgrc, and the current project’s configuration file is in the./.hg/ hidden directory. The path to the remote repository is recorded in./.hg/ HGRC.
Submitted to the user
Configure the signature when committing
## file ~/.hgrc
[ui]
username = zhang3 <[email protected]>
Develop management
HG extension management using INI format file management, internal extension only need to write the extension name is like a switch, use third party extension need to specify the extension file path.
[extensions]
shelve =
strip =
my_ext = ~/my_ext.py
Q&A
-
'hg status' failed with code 255: 'abort: repository requires features unknown to this Mercurial: sparserevlog !
This is asparse-revlog
Relevant error report
Note behind that sentence see https://www.mercurial-scm.org/wiki/MissingRequirement, after the visit you can see the compatibility between impassability version. If you want to use something like SourceTree, TortoiseHg, etc. The configuration needs to be adjusted.
- HG changed the configuration file, it did not take effect
If you want to use SourceTree, TortoiseHg, etc., you need to be careful about the path you want to change.
HG long head problem
This is usually due to the fact that there is no hg pull. An “abort: push creates a new remote head ** on branch **”
- No matter he,
hg update -b
.hg push -b
And the command is replaced withhg update -r
.hg push -r
, that is, specify a pushcommit
In this way, you can avoid multiple header branches with the same name. HG doesn’t know which branch you want to push, so you can directly specify the version number and continue to work. - Delete the extra heads
$hg strip -r (commit version number to be removed) '
How does HG roll back committed code
HG ROLLBACK can only rollback once a COMMIT that has not been committed to the remote.
We can do this by creating an opposite patch for the Commit we just committed and then importing the patch.
## create patch, for example: > rollback_commit.patch $hg diff-r (rollback commit version) -r (you need to rollback the previous commit version) ## import ROLLBACK PATCH $HG import ROLLBACK_COMMIT. PATCH -- NO-COMIT ## View reverse commit change $HG status
Okay, so you can see the pending rollback changes in your workspace. Check that it’s okay to submit it to the remote, and you’re done with this rollback.