mercurial_在10分钟内学习Mercurial版本控制基础知识

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.jsgit status类似的touch secondFile.js ,我们可以在此处使用hg status ,结果将如下所示:

Image for post
Result of 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将为您提供提交的简要历史记录。

Image for post
hg log result
汞日志结果

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显示一条消息:

Image for post
Mercurial merge message
水银合并消息

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感到更有信心! :)

翻译自: https://medium.com/javascript-in-plain-english/learn-mercurial-revision-control-basics-in-10-minutes-if-you-know-git-4466bd9d1fa9

mercurial

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值