Compare commits

...

42 Commits

Author SHA1 Message Date
11f7e06250 Merge branch 'master' of https://gitea.mhrooz.xyz/iicd/git-learner 2024-09-02 00:09:37 +02:00
fb0dd4d613 3.3 done 2024-09-02 00:09:29 +02:00
47fd86d4fa Merge pull request '0826 request merge' (#1) from danna/git-learner:master into master
Reviewed-on: #1
2024-08-26 13:56:20 +02:00
dan
4bb20fac5f 0826 request merge 2024-08-26 13:53:49 +02:00
8c6aed4ca1 blank commit 2024-08-25 22:05:19 +02:00
49c43b568f add notes 2024-08-25 00:00:06 +02:00
615467d28c add 2.9 notes 2024-08-22 20:13:03 +02:00
31f7a8f26d add 2.10 notes 2024-08-22 19:43:28 +02:00
c59ecd2869 sync test 4 2024-08-22 19:32:26 +02:00
18f2b57018 sync test 3 2024-08-22 19:32:14 +02:00
5f7b2c5779 sync test 2 2024-08-22 19:18:49 +02:00
0a3fecc92e sync test 1 2024-08-22 19:18:44 +02:00
6a398dcde8 Merge branch 'master' of https://gitea.mhrooz.xyz/iicd/git-learner 2024-08-21 01:13:35 +02:00
f9e486b837 Revert "modify Morgen.txt"
This reverts commit 37a4decc83.
2024-08-21 01:05:00 +02:00
37a4decc83 modify Morgen.txt 2024-08-20 23:20:31 +02:00
f2dd2b6d5c add hello.h 2024-08-20 23:19:55 +02:00
ca358d7dcb move .gitignore outside also works 2024-08-20 23:19:04 +02:00
572f5215ce ignore object files 2024-08-20 23:18:12 +02:00
9d867fc271 Hello world initialized 2024-08-20 23:17:24 +02:00
515dd2b9c4 README is from welcome.txt: 2024-08-20 23:16:50 +02:00
7fca44eac8 commit with --amend test. 2024-08-20 23:00:34 +02:00
ce2b85da59 test a test file 2024-08-20 22:56:59 +02:00
df3218e422 delete hello.h 2024-08-20 22:52:39 +02:00
73624ddf35 add hello.h to make an experiment 2024-08-20 22:50:36 +02:00
a4039843d6 test commit amend 2024-08-20 22:30:49 +02:00
a8029669af add git bisect part 2024-08-19 15:16:53 +02:00
7952818907 add git log notes 2024-08-19 11:19:14 +02:00
15c0ebbff6 add some notes about the rm 2024-08-19 11:05:07 +02:00
61d0e63490 test git rm --cached 2024-08-19 11:02:07 +02:00
c6700dec10 test git add -u to add the deleted file 2024-08-19 10:55:34 +02:00
7476f0a141 git add a removed file compared to the last commit 2024-08-19 10:54:37 +02:00
51bc20bac1 test git rm a existed file in last commit 2024-08-19 10:52:48 +02:00
81d8e86df1 test remove command 2024-08-19 10:50:44 +02:00
570f8b26ee save workspace 2024-08-19 10:49:44 +02:00
e8a66d4e72 Merge branch 'master' of https://gitea.mhrooz.xyz/iicd/git-learner 2024-08-19 09:51:30 +02:00
5032b7e8f1 add 2.8 notes 2024-08-19 09:51:21 +02:00
21e8c37152 Merge branch 'master' of https://gitea.mhrooz.xyz/iicd/git-learner 2024-08-19 09:50:49 +02:00
659bfc6fbc add 2.8 notes 2024-08-19 09:49:08 +02:00
22908a85ac test with qgit 2024-08-19 09:38:33 +02:00
07d5cbd029 update 2.7 notes 2024-08-18 23:35:59 +02:00
17844d154a Hello world initilized 2024-08-18 23:24:46 +02:00
dbda7e15b0 Hello world initilized 2024-08-18 23:13:18 +02:00
18 changed files with 510 additions and 2 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*.swp
*.h
hello
*.pyc

1
Morgen.txt Normal file
View File

@ -0,0 +1 @@
Guten Morgen

2
README
View File

@ -1,2 +1,4 @@
Hello.
Nice to meet you.
README
Nice to meet you too

1
hello.h Normal file
View File

@ -0,0 +1 @@
#include <stdio.h>

1
notes/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.pyc

49
notes/2.10-git_clone.md Normal file
View File

@ -0,0 +1,49 @@
## 2.10 git clone建立版本库克隆
### 2.10.1
!()[https://www.worldhello.net/gotgit/images/git-clone-pull-push.png]
```bash
git clone <repo> <dir>
git clone --bare <repo> <dir.git> # 不含工作区不注册不能用git fetch
git clone --mirror <repo> <dir.git> # 不含工作区注册可以用git fetch
```
```bash
git push [<remote-repos> [refspec>]]
git pull [<remote-repos> [refspec>]]
```
### 2.10.2 test
对本地的git仓库进行backup
```bash
git clone /path/to/my/workspace/demo /path/to/my/workspace/demo-backup
```
此时从主仓库到备用仓库中push是无法push的因为备用仓库不是bare repo用工作目录直接更新会导致工作目录和最新的commit不一致很奇怪。
此时应该从备用仓库中git pull。
git clone会自动在本地仓库中说明远程仓库是在哪
```bash
git remote -v
```
### 2.10.3 推送到裸仓库中
```bash
git push /path/to/bare/repo.git
```
### 2.10.4 创建裸版本仓库
```bash
git init --bare demo-init.git
```
```bash
git push /path/to/repo.git master:master #如果碰见没有指定的推送需要加上master:master
```

View File

@ -0,0 +1,3 @@
## 2.11 git库管理

View File

@ -1,6 +1,6 @@
## 2.7 Git Basic Ops
## 2.7.1 git tag
### 2.7.1 git tag
给当前的进度打个标签
```bash
@ -8,7 +8,7 @@ git tag -m "some message" <version-string>
git describe # 查看标签
```
## 2.7.2 Git 删除文件
### 2.7.2 Git 删除文件
git
```bash
@ -26,3 +26,71 @@ git ls-files --with-tree=HEAD^ # 父节点中的文件还在
git add -u #将版本库中的本地文件的变更记录到暂存区中
```
### 2.7.3 恢复删除的文件
```bash
git cat-file -p HEAD~1:filename > filename
```
### 2.7.4 移动文件
```bash
git mv welcome.txt README # git提供的git mv来移动文件
git commit -m "rename test" # 在输出的结果中可以查看改名前后两个文件的相似度
```
### 2.7.5 显示版本号
```bash
git describe # 展示版本号
```
```bash
git log --oneline --decorate -4 #在提交日志中显示提交对应的Tag
```
### 2.7.6 git add -i
```bash
git add -i #进入一个交互式的提交脚本
```
### 2.7.8 Git忽略
就是编辑.gitignore文件
可以设置全局忽略的文件位置
```bash
git config --global core.excludesfile /path/to/file
git config core.excludesfile
```
小trick,可以用cat快速写入一个文件
```bash
cat > .gitignore << EOF
hello
*.o
*.h
EOF
```
忽略语法
```text
# 这是注释行 —— 被忽略
*.a # 忽略所有以 .a 为扩展名的文件。
!lib.a # 但是 lib.a 文件或者目录不要忽略,即使前面设置了对 *.a 的忽略。
/TODO # 只忽略根目录下的 TODO 文件,子目录的 TODO 文件不忽略。
build/ # 忽略所有 build/ 目录下的文件。
doc/*.txt # 忽略文件如 doc/notes.txt但是文件如 doc/server/arch.txt 不被忽略。
```
### 2.7.9 Git Archive
```bash
git archive -o latest.zip HEAD # 根据最新的提交创建zip
git archive -o latest.zip HEAD src doc # 只将目录src doc放入zip中
git archive --format=tar --prefix=1.0/ v1.0 | gzip > foo-1.0.tar.gz
```

152
notes/2.8-git-gui.md Normal file
View File

@ -0,0 +1,152 @@
## git UI
### 2.8.4 git rev-parse
```bash
git rev-parse --symbolic --branches # 显示分支
git rev-parse --symbolic --tags # 显示里程碑
git rev-parse --symbolic --glob=refs/* # 显示所有的引用
```
`git rev-parse`可以将一个Git对象表达式表示为对应的SHA1哈希值
tag也分为两种lightweighted tag和annotated tag
```bash
git tag <tagname> # lighteweighted tag
git tag -a <tagname> -m <message> # annotated tag
```
两种的区别在于轻量标签只会有commit对象
标记标签会自己生成一个对象然后指向commit对象
所以下面的内容中,`git rev-parse`指令的参数A和A^0是不同的哈希
```bash
git rev-parse master refs/heads/master # 显示多个哈希
git rev-parse A refs/tags/A
git rev-parse A^{} A^0 A^{commit}
git rev-parse A^3 # ~<n> = <n> ^
```
### git rm / git add -u / git rm --cached
`git rm`会执行两个指令:
1. 删除文件(工作区中的)
2. 添加删除操作到暂存区
3. 有一个前提是文件必须已经被git所跟踪
`git add -u`是将工作区的已经被git跟踪的文件添加到暂存区,包括修改和删除
`git rm --cached`是将暂存区的移除出来,也就是让**Git停止跟踪文件**。也就是说如果文件之前已经在commit中无论文件是否被修改使用这个指令都能让Git停止跟踪文件
### 2.8.4.2 git rev-list
作用主要是研究不同版本之间的范围,主要就是哈希值
```bash
git rev-list --oneline A
git rev-list --oneline D F # 使用两个tag的并集
git rev-list --oneline ^G D # 排除这个版本和历史版本 等价于
git rev-list --oneline G..D # 连接两个版本
git rev-list --oneline B...C # 两个版本共同能够访问的除外
git rev-list --oneline B^@ # 提交的历史提交,自身除外
git rev-list --oneline B^! # 只看提交本身
```
### 2.8.4.3 git log
显示提交历史
参数代表版本范围
```bash
git log --oneline F^! D
```
**graph show**
```bash
git config alias.glog "log --graph"# 用别名
git glog --oneline
```
显示最近几条
```bash
git log -3 --pretty=oneline
```
显示提交的具体改动
```bash
git log -p -1
```
显示变更概要
```bash
git log --stat --oneline I..C #显示版本I到C的变更概要
```
显示参数
```bash
git log --pretty=raw -1 # 显示提交的原始数据,
git log --pretty=fuller -1 # 显示作者和提交者
git log --pretty=oneline # 提供最精简的日志输出
```
只是查看,分析某一次的提交,可以使用`git show`或者是`git cat-file`命令
```bash
git show D --stat # 展示里程碑D及其提交
git cat-file -p D^0 # 展示里程碑D及其提交
```
### 2.8.4.4 git diff
```bash
git diff B A # 比较B和A里程碑
git diff A # 比较工作区和里程碑A
git diff --cached A
git diff
git diff --cached
git diff HEAD
```
```bash
git diff --word-diff
```
### 2.8.4.5 git blame
可以追溯指出是谁在什么时候,什么版本引入的代码
```
git blame <filename>
git blame -L <n,m> <filename> # 查看某几行
```
### 2.8.4.6 git bisect
用于二分查找什么时候引入的代码
```bash
git bisect start # 开始二分查找
git bisect bad # 设置当前版本为坏版本
git bisect good G # 设置里程碑G为好版本
git bisect reset # 结束
```
标记错误,恢复
```bash
git bisect log > logfile # 打开logfile删除标记错误的行
git bisect reset
git bisect replay logfile # 用logfile恢复进度
```

View File

@ -0,0 +1,51 @@
## 2.9 改变历史
### 2.9.1 悔棋
`git commit --amend -m` 会将当前的暂存区staging area中的更改与上一次的提交合并为一个新的提交同时允许你修改提交信息。
```bash
git commit -amend -m "message" # 修改上次提交的message
```
添加一个误删的文件
```bash
git checkout HEAD^ -- <filename> # 从上次的提交恢复文件
git status
git commit --amend -m "message" # 将当前的修改添加到上次的提交中
```
### 2.9.2 多步悔棋
想要将最近的两个提交压缩为一个并把提交说明改为“modify hello.h”可以使用如下方法进行操作。
```bash
git reset --soft HEAD^^ # 重置到两次提交之前
git status
git commit -m "modify hello.h"
```
### 2.9.3 回到未来 git rebase
```bash
git cherry-pick # 从众多的提交中挑选出一个提交应用在当前的工作分支中
```
去掉某个commit
```bash
git checkout <commit> # 先切换到某次提交
git cherry-pick <commit> # 输入之后的提交
git checkout <branch> # 再切换回来
```
合并两次commit
```bash
git checkout [<tag>|<commit>]
git reset --soft HEAD^^ # 向前移动两次
git commit -C C # 提交重用C提交的提交说明
git cherry-pick E
git cherry-pick F
```

14
notes/3.1_git_protocal.md Normal file
View File

@ -0,0 +1,14 @@
## 3.1 Git Protocal
### 3.1.2
一般情况下,推送只允许“快进式”推送。
所谓快进式推送,就是要推送的本地版本库的提交是建立在**远程版本库相应分支的现有提交**基础上的,即远程版本库相应分支的最新提交是本地版本库最新提交的祖先提交。
```bash
git rev-list HEAD # 查看最新提交和历史提交
git ls-remote origin # 显示远程版本库引用对应的哈希值
```

View File

@ -0,0 +1,60 @@
## 3.2 resolve conflict
### 3.2.1 拉回操作中的合并
pull操作的第一阶段将共享版本库master分支的最新提交拉回到本地并且更新到本地版本库特定的引用。
第二阶段将本地分支master和共享版本库的本地跟踪分支origin/master进行合并操作。
push操作是将本地提交推送到共享版本库中。
`git pull = git fetch + git merge`
```bash
git merge [option...] <commit>...
```
### 3.2.2 自动合并
多个用户修改了不同的文件/相同文件的不同部分可以自动merge
1. 多个用户修改了不同的文件
2. 相同文件的不同部分(开头,结尾)
3. A用户移动文件B用户编辑文件自动merge会把编辑好的文件移动到对应位置
```bash
git fetch
git merge origin/master # origin/master就是共享版本库的本地分支
git push
```
### 3.2.3 逻辑冲突
存在逻辑冲突,需要在合并后进行单元测试
### 3.2.4 冲突解决
git pull以后会提示冲突文件如果忘记了用git status也可以
git会自动把冲突的位置用七个<和七个=以及七个>标记出来将他们删除掉修改成想要的代码就可以merge了
```bash
git log --oneline --graph -3
```
### 3.2.5 树冲突
文件处于不同状态,比如一个用户改名,另一个用户改成不同名字
```bash
git rm readme.txt
git rm doc/README.txt
git add README
```
本质上就是删除掉其他两个,留下来一个想要的

59
notes/3.3-git_touch.md Normal file
View File

@ -0,0 +1,59 @@
## 3.3 git 里程碑
### 3.3.1 显示里程碑
```bash
git tag # 显示里程碑
git tag -n1 # 显示1行里程碑的说明
git tag -l jx/v2* # 使用过滤器
```
```bash
git log --oneline --decorate # 查看提交对应的里程碑以及其他引用
```
```bash
git describe # 显示<tag>-<num-g<commit> <tag> name <num> commit num <commit> commit
```
```bash
git name-rev HEAD # 显示提交ID和其对应的一个引用 这里是HEAD和master
```
### 3.3.2 创建里程碑
```bash
git tag <tagname> [<commit>] # 轻量级里程碑
git tag -a <tagname> [<commit>]
git tag -m <msg> <tagname> [<commit>] # 带说明的里程碑
git tag -s <tagname> [<commit>]
git tag -u <key-id> <tagname> [<commit>] # 带GPG签名的里程碑
```
### 3.3.3 删除里程碑
```bash
git tag -d
```
### 3.3.4 不要更改里程
### 3.3.5 共享里程碑
```bash
git ls-remote origin my* # 查看以my开头的里程碑
```
```bash
git push origin mytag # 推送mytag到远端
git push origin refs/tags/* # 推送本地建立的所有里程碑
```
### 3.3.6 删除远端里程碑
```bash
git tag -d <tagname>
git push origin :<tagname>
```

27
src/Makefile Normal file
View File

@ -0,0 +1,27 @@
OBJECTS = main.o
TARGET = hello
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) -o $@ $^
main.o: | new_header
main.o: version.h
new_header:
@sed -e "s/<version>/$$(git describe)/g" \
<version.h.in> version.h.tmp
@if diff -q version.h.tmp version.h > /dev/null 2>&1; \
then \
rm version.h.tmp; \
else \
echo "version.h.in => version.h" ; \
mv version.h.tmp version.h;\
fi
clean:
rm -f $(TARGET) $(OBJECTS) version.h
.PHONY: all clean

8
src/main.c Normal file
View File

@ -0,0 +1,8 @@
#include "version.h"
#include <stdio.h>
int main(){
printf("Hello, world. \n");
printf("version: %s. \n", _VERSION);
return 0;
}

6
src/version.h.in Normal file
View File

@ -0,0 +1,6 @@
#ifndef HELLO_WORLD_VERSION_H
#define HELLO_WORLD_VERSION_H
#define _VERSION "<version>"
#endif

1
test Normal file
View File

@ -0,0 +1 @@
test

1
welcome.txt Normal file
View File

@ -0,0 +1 @@
Hello world