Skip to content

Git 常用命令

Git is an open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. It was created by Linus Torvalds in 2005 to manage the development of the Linux kernel. Unlike traditional version control systems like CVS and Subversion (SVN), Git uses a distributed architecture, which means every developer has a full copy of the repository, including its history, on their local machine.

Git 是什么

Git 是一个开源的分布式版本控制系统,旨在快速高效地处理从小型到非常大型的项目。它由 Linus Torvalds 于 2005 年创建,用于管理 Linux 内核的开发。与 CVS 和 Subversion (SVN) 等传统的版本控制系统不同,Git 使用分布式架构,这意味着每个开发人员在他们的本地机器上都有一个完整的仓库副本,包括其历史记录。

Git 基本命令

git init

git init 命令用于在当前目录中创建一个新的 Git 仓库。

git clone

git clone [url] 命令用于克隆一个远程仓库到本地。

git status

git status 命令用于显示工作目录和暂存区的状态。它可以让你看到哪些文件被修改了,哪些文件是新添加的,哪些文件被删除了。

git add

git add [file] 命令用于将文件的更改添加到暂存区。你可以指定一个文件名,也可以使用 git add . 来添加所有更改。

git commit

git commit -m "[commit message]" 命令用于将暂存区的更改提交到仓库中。提交信息应该清晰地描述这次提交的内容。

git log

git log 命令用于显示提交历史。你可以看到每次提交的作者、日期和提交信息。

git pull

git pull 命令用于从远程仓库拉取最新的更改。

git push

git push [remote] [branch] 命令用于将本地的提交推送到远程仓库。

git branch

git branch 命令用于列出、创建或删除分支。

  • git branch [branch-name]:创建一个新的分支。
  • git branch -d [branch-name]:删除一个分支。

git checkout

git checkout [branch-name] 命令用于切换到另一个分支 git checkout -b [new-branch-name] 命令可以创建一个新分支并立即切换到该分支。

git merge

git merge [branch] 命令用于将指定分支的历史合并到当前分支。

git remote 命令

git remote 命令用于用于管理 Git 仓库中的远程仓库。

git remote 命令提供了一些用于查看、添加、重命名和删除远程仓库的功能。

以下是 git remote 命令的常见用法:

  • git remote:列出当前仓库中已配置的远程仓库
  • git remote -v:列出当前仓库中已配置的远程仓库,并显示它们的 URL
  • git remote add <remote_name> <remote_url>:指定一个远程仓库的名称和 URL,将其关联到当前仓库
  • git remote rename <old_name> <new_name>:将已配置的远程仓库重命名
  • git remote remove <remote_name>:从当前仓库中删除指定的远程仓库
  • git remote set-url <remote_name> <new_url>:修改指定远程仓库的 URL
  • git remote show <remote_name>:显示指定远程仓库的详细信息,包括 URL 和跟踪分支
最近更新