基本命令

发布时间 2023-06-29 17:41:03作者: 黑逍逍

参考文档:https://www.rookiew.com/server/2743.html

Git配置(git config):

  • 修改个人信息:

    • git config --global user.name "Your Name":设置全局用户名
    • git config --global user.email "youremail@example.com":设置全局用户邮箱
  • 查看配置:

    • git config --list:列出当前所有的Git配置信息

Git基本操作:

  • 初始化仓库(git init):

    • 在当前目录下创建一个新的Git仓库:git init
  • 克隆(git clone):

    • 克隆远程仓库到本地:git clone <repository_url>
  • 暂存(git add):

    • 将文件添加到暂存区:git add <file_name>(添加单个文件)
    • 将所有文件添加到暂存区:git add .git add --all
  • 提交(git commit):

    • 提交暂存区中的文件到本地仓库:git commit -m "Commit message"
  • 推送(git push):

    • 推送本地仓库的提交到远程仓库:git push <remote_name> <branch_name>
  • 拉取(git fetch):

    • 从远程仓库获取最新的提交,但不自动合并到当前分支:git fetch
  • 拉取合并(git pull):

    • 从远程仓库获取最新的提交,并自动合并到当前分支:git pull
  • 查看状态(git status):

    • 查看当前仓库的状态:git status
  • 查看历史(git log):

    • 查看提交历史记录:git log

分支操作:

  • 创建分支:

    • 创建新的分支:git branch <branch_name>
  • 查看分支:

    • 查看当前仓库的所有分支:git branch
  • 切换分支:

    • 切换到指定分支:git checkout <branch_name>
  • 删除分支:

    • 删除指定分支:git branch -d <branch_name>
  • 合并分支:

    • 将指定分支合并到当前分支:git merge <branch_name>