Gitlab 简明教程

GitLab - Git Commands

Description

Git 命令用于轻松与其他开发人员共享和合并代码。

Git commands are used for sharing and combining the code easily with other developers.

Git Commands

以下是可用于处理 Git 的一些基本 Git 命令 −

Following are the some basic Git commands can be used to work with Git −

可以通过使用以下命令来检查 Git 的版本 −

The version of the Git can be checked by using the below command −

$ git --version

添加 Git 用户名和电子邮件地址,以便在提交信息时识别作者。通过使用以下命令设置用户名 −

Add Git username and email address to identify the author while committing the information. Set the username by using the command as −

$ git config --global user.name "USERNAME"

输入用户名后,通过以下命令验证输入的用户名 −

After entering user name, verify the entered user name with the below command −

$ git config --global user.name

接下来,使用以下命令设置电子邮件地址 −

Next, set the email address with the below command −

$ git config --global user.email "email_address@example.com"

你可以按照以下方式验证输入的电子邮件地址 −

You can verify the entered email address as −

$ git config --global user.email

使用以下命令检查输入的信息 −

Use the below command to check the entered information −

$ git config --global --list

可使用以下命令拉取已对主分支进行的最新更改 −

You can pull the latest changes made to the master branch by using the below command −

$ git checkout master

可使用以下命令获取对工作目录的最新更改 −

You can fetch the latest changes to the working directory with the below command −

$ git pull origin NAME-OF-BRANCH -u

此处,NAME-OF-BRANCH 可以是“master”或任何其他现有分支。

Here, NAME-OF-BRANCH could be 'master' or any other existing branch.

使用以下命令创建新分支 −

Create a new branch with the below command −

$ git checkout -b branch-name

可使用以下命令从一个分支切换到其他分支 −

You can switch from one branch to other branch by using the command as −

$ git checkout branch-name

使用以下命令检查所做的文件更改 −

Check the changes made to your files with the below command −

$ git status

你将看到以红色显示的更改,并将文件添加到暂存区,如 −

You will see the changes in red color and add the files to staging as −

$ git add file-name

或者你可以按照以下方式将所有文件添加到暂存区 −

Or you can add all the files to staging as −

$ git add *

现在,使用以下命令将你的更改发送到主分支 −

Now send your changes to master branch with the below command −

$ git push origin branch-name

使用以下命令删除除未暂存内容以外的所有更改 −

Delete the all changes, except unstaged things by using the below command −

$ git checkout .

可使用以下命令删除所有更改以及未跟踪的文件 −

You can delete the all changes along with untracked files by using the command as −

$ git clean -f

要将不同的分支与主分支合并,请使用以下命令 −

To merge the different branch with the master branch, use the below command −

$git checkout branch-name
$ git merge master

您还可以使用以下命令将主分支与已创建的分支合并 −

You can also merge the master branch with the created branch, by using the below command −

$git checkout master
$ git merge branch-name