当前位置: 首页 > news >正文

【学习笔记】Git常用命令

目录

  • Git常用命令
    • 1. git init (初始化一个新的Git仓库)
    • 2. git clone [url] (克隆远程仓库到本地计算机)
    • 3. git status (查看当前工作区的状态)
    • 4. git add [file] (将文件添加到暂存区)
    • 5. git commit -m "commit message" (提交暂存区中的更改)
    • 6. git log (查看提交历史记录)
    • 7. git diff (查看工作区与上次提交之间的代码差异)
    • 8. git remote -v (查看已配置的远程仓库及其URL)
    • 9. git remote add [remote-name] [url] (添加一个新的远程仓库)
    • 10. git push [remote-name] [branch-name] ( 将本地分支推送到远程仓库)
    • 11. git pull [remote-name] [branch-name] (从远程仓库拉取最新的更改并合并到本地分支)
    • 12. git fetch [remote-name] (从远程仓库获取最新的更改)
    • 13. git branch (查看本地分支列表)
    • 14. git checkout [branch-name] ( 切换到另一个分支或恢复工作树文件)
    • 15. git merge [branch-name] (将指定的分支合并到当前分支)

Git常用命令

1. git init (初始化一个新的Git仓库)

在项目目录中运行此命令,以便开始跟踪文件更改。

git init

2. git clone [url] (克隆远程仓库到本地计算机)

[url]替换为远程仓库的URL。

git clone https://github.com/user/repo.git

3. git status (查看当前工作区的状态)

查看已修改但未提交的文件。

git status

4. git add [file] (将文件添加到暂存区)

[file]替换为要添加的文件名。如果使用git add .,则会添加所有更改过的文件。

git add file.txt

5. git commit -m “commit message” (提交暂存区中的更改)

附上一条描述性的提交信息。

git commit -m "Add new feature"

6. git log (查看提交历史记录)

git log

7. git diff (查看工作区与上次提交之间的代码差异)

git diff

8. git remote -v (查看已配置的远程仓库及其URL)

git remote -v

9. git remote add [remote-name] [url] (添加一个新的远程仓库)

[remote-name]替换为远程仓库的名称,如origin,将[url]替换为远程仓库的URL。

git remote add origin https://github.com/user/repo.git

10. git push [remote-name] [branch-name] ( 将本地分支推送到远程仓库)

[remote-name]替换为远程仓库的名称,如origin,将[branch-name]替换为要推送的分支名称,如main

git push origin main

11. git pull [remote-name] [branch-name] (从远程仓库拉取最新的更改并合并到本地分支)

[remote-name]替换为远程仓库的名称,如origin,将[branch-name]替换为要拉取的分支名称,如main

git pull origin main

12. git fetch [remote-name] (从远程仓库获取最新的更改)

不进行合并。将[remote-name]替换为远程仓库的名称,如origin

git fetch origin

13. git branch (查看本地分支列表)

git branch

14. git checkout [branch-name] ( 切换到另一个分支或恢复工作树文件)

[branch-name]替换为要切换到的分支名称。

git checkout feature-branch

15. git merge [branch-name] (将指定的分支合并到当前分支)

将[branch-name]替换为要合并的分支名称。

git merge feature-branch
http://www.lryc.cn/news/365845.html

相关文章:

  • 【C/C++】IO流
  • Vite5+Vue3整合Tailwindcss详细教程
  • 小程序 UI 风格魅力非凡
  • 【常用工具系列】Git 教程——从入门到大师
  • 每天坚持写java锻炼能力---第一天(6.4)
  • mysql 如何分布式部署
  • Git的概念
  • 【每日刷题】Day58
  • Python 的七个HTTP请求库对比
  • 顶顶通呼叫中心中间件-如何配置识别不同语种的ASR
  • C# SolidWorks 二次开发-显示配置
  • PXE自动装机
  • MQ之初识kafka
  • linux驱动学习(七)之混杂设备
  • 【数据结构与算法 | 堆篇】力扣215, 703
  • 项目经理进入职场都会经历的三个阶段
  • 消防设施工程乙级资质全解析:申请条件与流程“
  • 【C语言】03.分支结构
  • uniapp手机屏幕左滑返回上一页支持APP,H5
  • 【Java毕业设计】基于JavaWeb的洗衣店管理系统
  • 使用sqlldr向oracle导入大量数据
  • Milvus LIKE操作符
  • iQOO neo 5精简内置组件
  • 为什么给网站安装SSL证书之后还是有被提示不安全?
  • 创建Frame单例,实现WPF页面跳转
  • 正宇软件助力江西数字人大建设,高效解决群众“急难愁盼”问题
  • 打造AIPC轻量化方案 360AI浏览器及360AI搜索全新发布
  • 《effective c++》学习笔记
  • 11.盛水最多的容器
  • 通过在idea上搭建虚拟hadoop环境使用MapReduce做词频去重