vault backup: 2024-02-19 16:40:58

This commit is contained in:
2024-02-19 16:40:58 +08:00
parent 4db1c51ae5
commit df520c0813
21 changed files with 381 additions and 124 deletions

View File

@@ -0,0 +1,36 @@
## apply
`git diff` 生出一個 diff 檔,而 `git apply` 把這個 diff 檔 apply 到某個 branch 上。
```
git diff ${A_COMMIT_HASH} ${B_COMMIT_HASH} > xxx.patch
git apply xxx.patch
```
- 如果在 `git apply` 的過程中遇到 trailing whitespace error 的話,可以參考這篇文章:[git - My diff contains trailing whitespace - how to get rid of it? - Stack Overflow](https://stackoverflow.com/questions/14509950/my-diff-contains-trailing-whitespace-how-to-get-rid-of-it),透過加入 `--whitespace=warn``--whitespace=nowarn` 參數來解決。
- [^1]
[^1]: [(2018 iThome 鐵人賽) Day 11: 使用 Git 時如何做出跨 repo 的 cherry-pick - iT 邦幫忙::一起幫忙解決難題,拯救 IT 人的一天](https://ithelp.ithome.com.tw/articles/10194972)
### Trouble shooting
- 如果在Windows上git clone遇到例如`error: invalid path``fatal: unable to checkout working tree`
```
$ gclogi git@github.com-logi:LogiVideoFW/VC_Bolide_TableHub.git
Cloning into 'VC_Bolide_TableHub'...
remote: Enumerating objects: 159, done.
remote: Counting objects: 100% (159/159), done.
remote: Compressing objects: 100% (134/134), done.
remote: Total 85001 (delta 71), reused 84 (delta 21), pack-reused 84842
Receiving objects: 100% (85001/85001), 599.21 MiB | 6.18 MiB/s, done.
Resolving deltas: 100% (17824/17824), done.
error: invalid path 'zynqLNX/kernel-source/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/aux.c'
fatal: unable to checkout working tree
warning: Clone succeeded, but checkout failed.
You can inspect what was checked out with 'git status'
and retry with 'git restore --source=HEAD :/'
```
有可能是因為檔名與NTFS規則有所衝突解法
```
cd <REPO_NAME>
git config core.protectNTFS false; git reset --hard HEAD
```

View File

@@ -0,0 +1,27 @@
## 建立 Git Submodule
```
git submodule add <repository> [<local_path>]
```
新增之後,用 git status 會發現多了兩個東西需要 commit
![[20220608152709_git_submodule.png|450]]
第一個檔案 .gitmodules裡面紀錄 submodule 的對應關係,內容大概像這樣:
```
[submodule "RobotRunQA"]
path = RobotRunQA
url = git@github.com-logi:JuiwenHsu/RobotRunQA.git
```
接下來剩3個步驟
1. 提交 `.gitmodule``git add .gitmodule ; git push origin master`
2. 跟git說我們有新增一個submodule`git submodule init`
3. 把submodule pull下來`git submodule update`
## Clone repository and submodule
當clone一個有submodule的repo的時候我們還需要 `git submodule init``git submodule update` ,例如:
```
git clone https://xxx/xxx.git
cd xxx
git submodule init
git submodule update
```

View File

@@ -0,0 +1,61 @@
## 列出你的標籤
```
$ git tag
v0.1
v1.3
```
## 建立新的標籤
```console
$ git tag -a v1.4 -m "my version 1.4"
$ git tag
v0.1
v1.3
v1.4
```
## 輕量級標籤
如果想要建立一個輕量級的標籤,不要指定 `-a``-s` 或 `-m` 的選項如下:
```console
$ git tag v1.4-lw
$ git tag
v0.1
v1.3
v1.4
v1.4-lw
v1.5
```
## 分享標籤
`git push` 指令預設不會傳送標籤到遠端伺服器。 在你建立標籤後,你必須明確的要求 Git 將標籤推送到共用的伺服器上面。 這個動作就像是在分享遠端分支一樣——你可以執行 `git push origin [tagname]`
```console
$ git push origin v1.5
Counting objects: 14, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (12/12), done.
Writing objects: 100% (14/14), 2.05 KiB | 0 bytes/s, done.
Total 14 (delta 3), reused 0 (delta 0)
To git@github.com:schacon/simplegit.git
* [new tag] v1.5 -> v1.5
```
如果想要一次推送很多標籤,也可以在使用 `git push` 指令的時候加上 `--tags` 選項。 這將會把你所有不在伺服器上面的標籤傳送給遠端伺服器。
```console
$ git push origin --tags
Counting objects: 1, done.
Writing objects: 100% (1/1), 160 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To git@github.com:schacon/simplegit.git
* [new tag] v1.4 -> v1.4
* [new tag] v1.4-lw -> v1.4-lw
```
## 檢出標籤
在 Git 中你不能真的檢出一個標籤,因為它們並不能像分支一樣四處移動。 如果你希望工作目錄和版本庫中特定的標籤版本完全一樣,你可以使用 `git checkout -b [branchname] [tagname]` 在該標籤上建立一個新分支:
```console
$ git checkout -b version2 v2.0.0
Switched to a new branch 'version2'
```
當然,如果在建立新分支以後又進行了一次提交,`version2` 分支將會和 `v2.0.0` 標籤有所差異,因為這個分支已經因為你的提交而改變了,請特別小心。