Lazy loaded image
🌉开发框架搭建
开发框架06-集成GIT版本控制系统
Words 2933Read Time 8 min
2024-10-26
2024-11-26
type
date
slug
category
icon
password

FAQs

1.切换成 https协议连接github
2. github连接报"ssh: connect to host github.com port 22: Connection timed out"错误
首先找到git的安装目录,找到/etc/ssh/ssh_config文件,然后再把这段
Host github.com
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443
写入到文本即可
3. fatal: refusing to merge unrelated histories
git merge master --allow-unrelated-histories
git pull origin master --allow-unrelated-histories
 
4. 将子 repo 添加到主 repo中
5. Github 图片加载不出
主要因为IP地址解析出错,可以通过更改host文件制定域名对应的IP地址

1. 查出对应域名的网址

复制 raw.githubusercontent.comhttps://www.ipaddress.com 搜索,把给出的IP地址存储到 host 文件中: 199.232.28.133 raw.githubusercontent.com
192.30.255.112 github.com git 185.31.16.184 github.global.ssl.fastly.net
125.120.42.110这个IP地址需要修改成你的IP地址,点击
查询,即可找到你的IP地址
13.229.188.59这个IP地址需要修改为GitHub的IP地址,即你执行
命令时,展示出的IP,如下图红线标注所示:

2. 修改host文件

地址:C:\Windows\System32\drivers\etc

3. 刷新本地DNS缓存

7. git 官网下载缓慢
安装包下载地址:https://gitforwindows.org/
官网慢,可以用国内的镜像:https://npm.taobao.org/mirrors/git-for-windows/
git 路径中文显示为数字
 

Brief Introduction

 
 
notion image
 
notion image

Introduction

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Git is easy to learn and has a tiny footprint with lightning fast performance. It outclasses SCM tools like Subversion, CVS, Perforce, and ClearCase with features like cheap local branching, convenient staging areas, and multiple workflows.
 
notion image
notion image
 
Features
https://git-scm.com/about/branching-and-merging
 
Staging Area
Unlike the other systems, Git has something called the "staging area" or "index". This is an intermediate area where commits can be formatted and reviewed before completing the commit.
 
Quickly stage some of your files and commit them without committing all of the other modified files in your working directory
Quickly stage some of your files and commit them without committing all of the other modified files in your working directory
just add a '-a' to your commit command in order to add all changes to all files to the staging area.
just add a '-a' to your commit command in order to add all changes to all files to the staging area.
This allows you to stage only portions of a modified file. Gone are the days of making two logically unrelated modifications to a file before you realized that you forgot to commit one of them. Now you can just stage the change you need for the current commit and stage the other change for the next commit. This feature scales up to as many different changes to your file as needed.
 
Common Workflow
  1. Subversion-Style Workflow
notion image
2. Integration Manager Workflow (open source or Github repositories)
notion image
3. Dictator and Lieutenants Workflow (linux kernel)
notion image
 
sudo apt install git

01. git init

 

02. git config

local ./git/config
global ~/.gitconfig
system /etc/gitconfig
从低级别确定

03. File Status Lifecycle

notion image
Hash 值
Location: .git/objects/[filename](The two first characters of hash value)
Check Command:
 
echo “se”
notion image

04. Git Commit Time Metaphor

4.1 ⭐ git reset --hard

  • git add 命令提交到暂存区,git reset HEAD demo1就是把提交到暂存区里的文件撤销
  • git commit 提交本地仓库,git reset –-hard HEAD^,撤销会把本地文件也会删除,如下操作可回复
    • git commit 提交本地仓库,git reset —soft HEAD^,会撤销commit,本地的保存还在,也就是变回待提交状态

    05. Git Delete Command

    All the files (new-modified) you want to include in the next commit have to be staged using the git add command
    Git reset is a powerful command, and it can be completely destroy your actual work if used improperly. Do not play with it if you don't know exactly what you are doing
    unstaging file

    06. Git Branching

     
    notion image
    notion image

    07. Git Stash

    两个分支进行开发,一个分支已开发但未提交的功能会影响到另一分支在开发调试时的本地编译,因此需要
     

    08. Git.ignore file

     
    解决方法: git清除本地缓存(改变成未track状态),然后再提交:- 我直接重新来了。搞定
    需要特别注意的是:
    1).gitignore只能忽略那些原来没有被track的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的。
    2)想要.gitignore起作用,必须要在这些文件不在暂存区中才可以,.gitignore文件只是忽略没有被staged(cached)文件,
    对于已经被staged文件,加入ignore文件时一定要先从staged移除,才可以忽略。

    09. Git working with remotes

    notion image

    9.1 添加到远程仓库(Gitee为例)

    1. gitee.com 网站创建仓库(按指示先设置用户名和邮箱,我们这里已经创建了本地仓库,只需要git remote操作后推送内容到远程仓库)
      1. notion image
    1. 若本地仓库尚未创建,初始化,添加add 并提交首次commit后,即可添加到远程仓库

      9.2 子模块管理

      目标
      1. 子模块修改可以提交远程代码库
      1. 其他项目可以获取子模块最新提交
      子模块
      添加子模块
      生成两个文件 .gitmodules (记录了子项目的目录和子项目的git地址信息)和 lettershell
      两个文件都需要提交到父项目的git中
       
      更新子模块
       
      克隆子模块

      10. Git remote operation

      10.1 协作 git pull 防止覆盖

      本地修改和远端仓库修改,git pull 覆盖本地

      11. 同时操作多个remote,本地如何同步到remote

       
       
      基于github搭建博客系统

      Reference

      1. tutorialspoint Git - Quick Guide (English Verson)
      1. An Intro to Git and GitHub for Beginners (Step-to-Step Tutorial)
      1. runoob.com Git 教程(chinese Version)
      1. Github Guides (Systematic and Brilliant)
      1. 汪文君Git实战视频
      1. 廖雪峰 Git讲解
       
       
      上一篇
      开发框架05-自动化测试
      下一篇
      开发框架07- Doxygen 文档生成

      Comments
      Loading...