mercurial
If you are using git
as a version control tool, you can learn the basics of Mercurial
as easy as pie. I was wondering if their motto(Work Easier Work Faster) is true or not and I determined to do basic version control actions using mercurial
just by using--help
and it worked like a charm!
如果您将git
用作版本控制工具,则可以轻松学习Mercurial
的基础知识。 我想知道他们的座右铭(Work Easier Work Faster)是否正确,我决定仅通过--help
使用mercurial
进行基本的版本控制操作,它的工作原理就像一个魅力!
安装 (Installation)
Doesn't need any explanation: sudo apt install hg
.
不需要任何解释: sudo apt install hg
。
If you are using other operating systems this link may help you.
如果您使用的是其他操作系统,则此链接可能会对您有所帮助。
If everything goes well you can see the version using hg --version
如果一切顺利,您可以使用hg --version
查看版本
配置Mercurial (Config mercurial)
After the installation, we need to add a user (just like Git) using this command:
安装后,我们需要使用以下命令添加一个用户(就像Git一样):
hg config --edit
And in the config file just fill username and you can start using Mercurial:
然后在配置文件中填写用户名,即可开始使用Mercurial:
初始化存储库 (Initialize a repository)
Use this command: hg init
.
使用以下命令: hg init
。
Now you are on the default
branch which is similar to master
in git.
现在您在default
分支上,它类似于git中的master
。
If you want to be sure use this command: hg branch
and this will show you: default
如果您想确定使用以下命令: hg branch
,它将向您显示: default
创建一个文件并提交该文件 (Create a file and commit that file)
You can create your file inside the folder or with using this command in Linux or Mac OS: touch myFirstFile.js
.
您可以在文件夹中创建文件,也可以在Linux或Mac OS中使用此命令创建文件: touch myFirstFile.js
。
Now, this file is untracked. We can use theAdd
command to make mercurial track this file: hg add ./myFirstFile.js
.
现在,该文件已取消跟踪。 我们可以使用Add
命令使该文件跟踪: hg add ./myFirstFile.js
。
Create another file but don’t add that file. For example touch secondFile.js
similar to git status
we can use hg status
here and the result will be like this:
创建另一个文件,但不要添加该文件。 例如, touch secondFile.js
与git status
类似的touch secondFile.js
,我们可以在此处使用hg status
,结果将如下所示:
Our first file which is added is showing with capital A(Which I assume it means Added!) and the second file(Which we created but didn’t add) is showing by a question mark.
我们添加的第一个文件以大写A表示(我认为这意味着添加!),第二个文件(我们创建但未添加的)以问号显示。
To commit that file we must use: hg commit --message "my first commit message"
. Now if you use: hg status
again you can see that file is gone.
要提交该文件,我们必须使用: hg commit --message "my first commit message"
。 现在,如果您再次使用: hg status
,则可以看到该文件已消失。
Question: How can I see my previous commits?Answer: Exactly like what you do on Git
问题 : 如何查看以前的提交 ? 答 :就像您在Git上所做的一样
hg log
will give you a brief history of your commits.
hg log
将为您提供提交的简要历史记录。
changeset
is something similar to a Git commit hash.
changeset
与Git提交哈希类似。
创建一个分支并将其合并为默认值 (Create a branch and merge that to default)
First check that you are in default branch:hg branch
the result should be default
.
首先检查您是否在default分支中: hg branch
结果应为default
。
Create a branch:hg branch branchName
.
创建一个分支: hg branch branchName
。
In Git you needed a -b
option to create and checkout to that branch branch -b branchName
but here you don’t need an option and after creating a branch your current branch is what you just created. Now the result of hg branch
should be your branch name.
在Git中,您需要一个-b
选项来创建和签出该分支branch -b branchName
但是在这里您不需要任何选项,并且在创建分支之后,当前分支就是您刚刚创建的分支。 现在, hg branch
的结果应该是您的分支名称。
Switch branches:Simply by using this command: hg update branchName
.
切换分支:只需使用以下命令: hg update branchName
。
Let’s create a file in this branch and commit that file.
让我们在此分支中创建一个文件并提交该文件。
touch thirdFile.js
hg add thirdFile.js
hg commit thirdFile.js
Now we want to merge our branch to default branch. First, we need to change our current branch:hg update default
. Second, we need to merge our branch: hg merge -r myBranchName
. Why -r
? -r
means revision.
现在我们想将分支合并到默认分支。 首先,我们需要更改当前分支: hg update default
。 其次,我们需要合并分支: hg merge -r myBranchName
。 为什么-r
? -r
表示修订。
After the merge Mercurial shows a message:
合并后,Mercurial显示一条消息:
My branch name is dev
. I had a file in my branch named thirdFile.js
and after the merge command, it has a capital M at the beginning when I use hg status
to see my working directory files (I assume that means Merge?!).And the message says clearly that I have to commit this merge:
我的分支名称是dev
。 我在我的分支中有一个文件名为thirdFile.js
,在执行合并命令之后,当我使用hg status
来查看我的工作目录文件时,它的开头为大写M(我认为这意味着Merge ?!)。显然,我必须提交此合并:
hg commit --message "merge branch"
Now the default branch is updated and it contains our thirdFile.js
.
现在, 默认分支已更新,其中包含我们的thirdFile.js
。
克隆远程存储库 (Clone a remote repository)
Mercurial has a test repository and you can easily clone it by using this command:
Mercurial有一个测试库,您可以使用以下命令轻松克隆它:
hg clone https://www.mercurial-scm.org/repo/hello
Push and pull are mostly the same as git
and I’m going to write a separate article about them.
推和拉与git
相同,我将撰写有关它们的单独文章。
And there you have it! Now you will hopefully feel more confident about using Mercurial! :)
在那里,您拥有了! 现在,您希望对使用Mercurial感到更有信心! :)
mercurial