0%

在 Git 中,分支操作是一个非常重要的部分,它允许你在开发过程中创建、合并和删除分支,以便更好地管理代码的不同版本和功能。以下是一些常见的 Git 分支操作及其用法:

1. 创建分支

创建一个新的分支:

1
git branch <branch_name>

例如:

1
git branch feature-xyz

2. 切换分支

切换到指定分支:

1
git checkout <branch_name>

例如:

1
git checkout feature-xyz

从Git 2.23版本开始,你可以使用更直观的 git switch 命令:

1
git switch <branch_name>

3. 创建并切换到新分支

创建并切换到新分支:

1
git checkout -b <branch_name>

或者:

1
git switch -c <branch_name>

4. 查看分支

列出所有分支:

1
git branch

列出所有远程分支:

1
git branch -r

列出所有本地和远程分支:

1
git branch -a

5. 合并分支

将指定分支合并到当前分支:

Who are you?

Every Git commit includes the author’s name and e-mail. Make sure Git knows your name and email by running these two commands:

1
2
git config --global user.name "csmtc"
git config --global user.email csmtc@outlook.com

git log

git log is a command for looking at the history of your repository. To create a special version of git log that summarizes the history of your repo, let’s create a git lol alias using the command (all on one line):

说明:本文所有master均可以用main替代

概念

VCS:Version control is a system that records changes to a file or set of files over time 用途:Git is a version control system (VCS). The Pro Git book describes what Git is used for:

  • you can recall specific versions later (recall selected files or entire project)
  • compare changes over time
  • see who last modified something that might be causing a problem
  • if you screw things up or lose files, you can easily recover.

Some of the most important Git concepts: