• Git


    参考:Github 官方文档

    参考:Git 官方文档

    参考教程:Git 入门指南关于 GitGit Bash的简单使用教程

    基础操作命令表:Git cheat sheet

    我使用的是 Windows 的 Git Bash

    对于本地的 Git 的工作,抽象的理解下就行,先本地 add 再 commit,最后 push 到远程仓库就好了

    PS:本文没有记载任何与撤回有关的任何信息,需要的请看官方文档

    配置工具

    # 为计算机上的每个仓库设置 Git 用户名
    git config --global user.name "CourserLi"
    # 为计算机上的每个仓库设置 Git 邮箱
    git config --global user.email "1480589612@qq.com"
    # 启用有帮助的彩色命令行输出
    git config --global color.ui auto
    # 解除 SSL 验证
    git config --global http.sslVerify "false"
    # 解决连不上 Github 的问题(先设置代理,再取消代理)
    git config --global https.proxy
    git config --global --unset https.proxy
    # 解决 OpenSSL SSL_read 10054 报错问题
    git config http.postBuffer 524288000
    

    开始操作

    # 开始设置本地仓库
    cd yourProject
    git init
    # 对目录内容进行快照
    git add .
    # 将快照存储在 index(临时仓库区)中
    git commit -m "something description"
    # 查看流程树
    gitk
    

    进行更改

    # 再添加文件
    git add file1 file2 file3
    # 删除文件
    git rm --cached <file>
    # 查看目录当前状态和上一次 commit 的版本有什么不同
    git diff --cached
    # 查看当前状态(和上面的命令类似)
    git status
    # 查看 commit 历史
    git log
    # 查看 commit 历史简约版(从新至旧)
    git log --stat --summary
    # 查看 commit 历史详细版
    git log -p
    # 列出文件的版本历史,包括重命名
    git log --follow [file]
    # 展示两个分支之间的内容差异
    git diff [first-branch]...[second-branch]
    # 展示两个分支之间的内容差异
    git show [first-branch]...[second-branch]
    

    分支

    # 查看全部分支(注意分支与 master 的内容不能完全相同)
    git branch
    # 创建分支
    git branch experimental
    # 切换分支
    git switch experimental
    # 合并分支进 master
    git merge experimental
    # 删除分支
    git branch -d experimental
    # 分支重命名
    git branch -M main
    

    同步更改

    # 克隆项目(下载所有分支)
    git clone https://github.com/YOUR-USERNAME/Spoon-Knife myRepo
    git clone git://github.com/YOUR-USERNAME/Spoon-Knife myRepo
    # 远程连接 GitHub(origin 是本地项目代称)
    git remote add origin https://github.com/YOUR-USERNAME/YOUR-REPOSITORY-NAME.git
    # 查看远程关联信息
    git remote -v
    # 退出远程连接
    git remote rm origin
    # 将本地项目上传到远程(传 origin 到 main)
    git push --set-upstream origin main
    # 将本地项目全部更改上传到远程
    git push
    # 将远程项目下载到本地(相当于 git fetch + git merge)
    git pull
    # 将远程项目的 commit 同步到本地
    git fetch
    # 将 commit 合并(一般用 git diff origin/main main 确认没问题就可以合并)
    git merge
    

    实例

    一、参与现有存储库,使用分支

    git clone https://github.com/owner/repo.git
    
    # 进入目录
    cd repo
    
    # 创建分支
    git branch my-branch
    
    # 进入分支
    git checkout my-branch
    
    # 做一些更改,比如用更改 file1.md 和 file2.md 文件
    
    # 暂存更改的文件
    git add file1.md file2.md
    
    # 进行 commit
    git commit -m "my snapshot"
    
    # 远程 push 到 github
    git push --set-upstream origin my-branch
    

    二、启动新存储库并将其发布到 GitHub

    # 在当前目录下创建新文件夹 my-repo 作为 git 的工作区
    git init my-repo
    
    # 进入目录
    cd my-repo
    
    # 创建第一个文件
    touch README.md
    
    # 加入暂存区
    git add README.md
    
    # 进行 commit
    git commit -m "add README to initial commit"
    
    # 分支重命名
    git branch -M main
    
    # 远程连接到 GitHub
    git remote add origin https://github.com/YOUR-USERNAME/YOUR-REPOSITORY-NAME.git
    
    # 远程 push 到 github
    git push --set-upstream origin main
    

    三、为 GitHub 的现有分支做出贡献

    # 进入目录
    cd repo
    
    # 将远程仓库拉进来,更新本地仓库
    git pull
    
    # 进入现有分区
    git checkout feature-a
    
    # 做一些更改,比如用更改 file1.md 文件
    
    # 加入暂存区
    git add file1.md
    
    # 进行 commit
    git commit -m "edit file1"
    
    # 远程 push 到 github
    git push
    

    四、自己真实的例子(导入 Manim 项目进入 Github 仓库)

    # 在 Github 创建 new repository
    
    # 进入目录
    cd /d/Projects/Manim制作/Manim
    
    # 创建 Git 工作区
    git init
    
    # 添加全部文件进入暂存区
    git add .
    
    # 进行 commit
    git commit -m "First commit all codes"
    
    # 分支重命名
    git branch -M main
    
    # 远程连接到 GitHub
    git remote add origin https://github.com/CourserLi/Manim.git
    
    # 远程 push 到 github
    git push --set-upstream origin main
    
  • 相关阅读:
    2.DI依赖注入
    1.Spring框架入门案例
    5.通过参数注解多个接口参数的用法
    4.update更新和delete删除用法
    3.insert添加用法
    git基础操作
    2.mongodb可视化工具
    12.Scrapy与mongodb交互和设置中间键
    WPF 学习系列汇总
    WPF 4.0 DatePicker 快速录入
  • 原文地址:https://www.cnblogs.com/CourserLi/p/16135073.html
Copyright © 2020-2023  润新知