type
date
slug
category
icon
password
FAQsBrief IntroductionIntroduction01. git init02. git config03. File Status Lifecycle04. Git Commit Time Metaphor4.1 ⭐ git reset --hard 05. Git Delete Command06. Git Branching07. Git Stash08. Git.ignore file09. Git working with remotes9.1 添加到远程仓库(Gitee为例)9.2 子模块管理10. Git remote operation10.1 协作 git pull 防止覆盖11. 同时操作多个remote,本地如何同步到remoteReference
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
User [email protected]
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
5. Github 图片加载不出
主要因为IP地址解析出错,可以通过更改host文件制定域名对应的IP地址
1. 查出对应域名的网址
复制 raw.githubusercontent.com 去 https://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/。
Brief Introduction


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.


Features

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.


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
- Subversion-Style Workflow

2. Integration Manager Workflow (open source or Github repositories)

3. Dictator and Lieutenants Workflow (linux kernel)

sudo apt install git
01. git init
02. git config
local ./git/config
global ~/.gitconfig
system /etc/gitconfig
从低级别确定
03. File Status Lifecycle

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

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


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

9.1 添加到远程仓库(Gitee为例)
- gitee.com 网站创建仓库(按指示先设置用户名和邮箱,我们这里已经创建了本地仓库,只需要git remote操作后推送内容到远程仓库)

- 若本地仓库尚未创建,初始化,添加add 并提交首次commit后,即可添加到远程仓库
9.2 子模块管理
目标
- 子模块修改可以提交远程代码库
- 其他项目可以获取子模块最新提交
添加子模块
生成两个文件 .gitmodules (记录了子项目的目录和子项目的
git
地址信息)和 lettershell两个文件都需要提交到父项目的git中。
更新子模块
克隆子模块
10. Git remote operation
10.1 协作 git pull 防止覆盖
本地修改和远端仓库修改,git pull 覆盖本地
11. 同时操作多个remote,本地如何同步到remote
Reference
- tutorialspoint Git - Quick Guide (English Verson)
- An Intro to Git and GitHub for Beginners (Step-to-Step Tutorial)
- runoob.com Git 教程(chinese Version)
- Github Guides (Systematic and Brilliant)
- Author:felixfixit
- URL:http://www.felixmicrospace.top/article/mcu_devframe_git
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!