首页 经验

常用的git命令

时间: 2024-10-21 10:54:32

(部分内容来自网络,其真实性存疑,为了避免对您造成误导,请谨慎甄别。)

Git 是一个强大的版本控制系统,常用的 Git 命令可以帮助你管理和控制代码版本。以下是一些常用的 Git 命令及其简要说明:


1. 基本命令


- 初始化一个新的 Git 仓库

 

bash

  git init

 


- 克隆一个远程仓库

 

bash

  git clone <repository-url>

 


- 查看当前 Git 配置信息

 

bash

  git config -l

 


2. 版本控制命令


- 查看当前状态

 

bash

  git status

 


- 添加文件到暂存区

 

bash

  git add <file>            # 添加指定文件

  git add .                 # 添加当前目录下所有更改的文件

 


- 提交更改

 

bash

  git commit -m "commit message"

 


- 查看提交历史

 

bash

  git log

 


- 查看更改的文件

 

bash

  git diff                   # 查看未暂存的更改

  git diff --cached          # 查看已暂存的更改

 


3. 分支管理


- 查看所有分支

 

bash

  git branch

 


- 创建新分支

 

bash

  git branch <branch-name>

 


- 切换到指定分支

 

bash

  git checkout <branch-name>

 


- 创建并切换到新分支

 

bash

  git checkout -b <branch-name>

 


- 合并分支

 

bash

  git merge <branch-name>

 


- 删除分支

 

bash

  git branch -d <branch-name>

 


4. 远程仓库管理


- 查看远程仓库信息

 

bash

  git remote -v

 


- 添加远程仓库

 

bash

  git remote add <name> <repository-url>

 


- 推送到远程仓库

 

bash

  git push <remote-name> <branch-name>

 


- 从远程仓库拉取更新

 

bash

  git pull <remote-name> <branch-name>

 


- 获取远程仓库信息而不合并

 

bash

  git fetch <remote-name>

 


5. 标签


- 创建标签

 

bash

  git tag <tag-name>

 


- 查看标签

 

bash

  git tag

 


- 推送标签到远程

 

bash

  git push <remote-name> <tag-name>

 


6. 其他常用命令


- 撤销已暂存的更改

 

bash

  git reset <file>          # 从暂存区移除文件,但保持本地更改

 


- 撤销本地修改

 

bash

  git checkout -- <file>    # 还原文件到上一次提交的状态

 


- 在暂存区与工作区之间恢复文件

 

bash

  git restore <file>

 


7. 查看帮助


- 查看 Git 命令帮助

 

bash

  git help <command>          # 例如:git help commit

 


这些是 Git 的一些常用命令,掌握这些基本命令可以有效地管理你的代码版本和协作开发。


上一个 js 判断数据类型的几种方法 文章列表 下一个 es6新特性

最新

工具

© 2019-至今 适观科技

沪ICP备17002269号