git
git
高级¶
- 从一个节点产生多个分支,能否 rebase 新的 cm 到该节点?
reset 后恢复 reflog¶
reset --soft, --mixed, --hard¶
修改的不同阶段:
- in working directory:
- index / stagged:通过 git add
- commited:进入版本控制,commited 的修改总能找回来。
--soft B:将 C 的修改恢复到 index 中 --mixed B:将 C 的修改恢复到 working directory 中 --hard B:index 被修改为 B,working directory 清空
git co 和 git reset --mixed 效果类似,都能保留当前 working directory,同时还能保留 git log。
rebase¶
Q: git X 分支有 A, B, C 三个提交,Y 分支有 A, B2 两个提交,如何将 X 分支 rebase 到 B2。其中 B 和 B2 存在冲突 A:
-Y
是你要将提交移到的分支(即 B2
之后)。
- B
是你想要忽略的基提交(B
会被替换为 B2
)。
- X
是当前分支。
git rb --onto local/main ddcfc5d memory
First, rewinding head to replay your work on top of it...
Applying: rewrite PPT-GPU get_max_active_block
Applying: run sim error print output to stderr
tag¶
#显示所有tag
git tag
#显示具体tag信息
git show v1.2
#添加tag
git tag v1.2 9fceb02 -a
git tag v1.2 9fceb02 -a -m "my tag"
#删除tag
git tag -d v1.2
#推送tag到远程
git push origin --tags
小技巧¶
shallow clone¶
避免 clone 的仓库太大,将 git commit 记录截断。
man git-clone
Create a shallow clone with a history truncated to the specified number of commits. Implies --single-branch
unless --no-single-branch
is given to fetch the histories near the tips of all branches. If you want to clone submodules shallowly, also pass shallow-submodules
.
代理¶
查看详细信息¶
GIT_TRACE=1
git --verbose <cmd>
http 和 https 设置代理¶
ssh 代理¶
windows¶
windows 下没有 nc 命令,需要 connect.exe(可以下载.c 文件编译成 exe 文件)
SSH in git behind proxy on windows 7 - Stack Overflow
遇到的问题¶
unsafe directory¶
git - Fatal error "unsafe repository ('/home/repon' is owned by someone else)" - Stack Overflow
git version > Git 2.36
git config --global --add safe.directory '*'
curl 92 HTTP/2 stream 0 was not closed cleanly: CANCEL (err 8)¶
➜ repo git clone https://github.com/YaoFANGUK/video-subtitle-generator
Cloning into 'video-subtitle-generator'...
remote: Enumerating objects: 434, done.
remote: Counting objects: 100% (95/95), done.
remote: Compressing objects: 100% (53/53), done.
error: RPC failed; curl 92 HTTP/2 stream 0 was not closed cleanly: CANCEL (err 8)
error: 503 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output
成功
➜ repo git clone https://github.com/YaoFANGUK/video-subtitle-generator
Cloning into 'video-subtitle-generator'...
remote: Enumerating objects: 434, done.
remote: Counting objects: 100% (95/95), done.
remote: Compressing objects: 100% (53/53), done.
remote: Total 434 (delta 46), reused 87 (delta 42), pack-reused 339
Receiving objects: 100% (434/434), 5.92 GiB | 21.39 MiB/s, done.
Resolving deltas: 100% (149/149), done.
Updating files: 100% (151/151), done.
貌似修改 buffer 也可以:GIT 推送错误 error: RPC failed;curl 92 HTTP/2 stream 0 was not closed cleanly: CANCEL (err 8) - 郭小睿 - 博客园 (cnblogs.com)
patch 补丁¶
Git 打补丁-- patch 和 diff 的使用(详细) - 掘金 (juejin.cn)
Git 提供了两种补丁方案,一是用 git diff 生成的 UNIX 标准补丁.diff 文件,二是 git format-patch 生成的 Git 专用.patch 文件。 .diff 文件只是记录文件改变的内容,不带有 commit 记录信息,多个 commit 可以合并成一个 diff 文件。 .patch 文件带有记录文件改变的内容,也带有 commit 记录信息,每个 commit 对应一个 patch 文件。
git format-patch HEAD^ # 最新的一次 commit(上一次到现在的 commit)
git format-patch 【commit sha1 id】..【commit sha1 id】 # 某两次提交之间的所有patch
-o
: If -o is specified, output files are created in dir. Otherwise they are created in the current working directory-n
: -n, --numbered Name output in [PATCH n/m] format, even with a single patch.
git diff 相关
git diff 【commit sha1 id】 【commit sha1 id】 > 【diff文件名】
git diff --no-index file1 file2 # 非git repo下,生成两个文件diff
format-patch¶
Git - git-format-patch Documentation (git-scm.com)
git format-patch HEAD^ # 最新的一次 commit(上一次到现在的 commit)
git format-patch 【commit sha1 id】..【commit sha1 id】 # 某两次提交之间的所有patch
应用 patch
submodule¶
可以本地添加 submodule
添加 submodule 后会生成.gitmodules
文件
[submodule "third-party/gpu-rodinia"]
path = third-party/gpu-rodinia
url = ./third-party/gpu-rodinia
[submodule "third-party/nvbit_release"]
path = third-party/nvbit_release
url = ./third-party/nvbit_release
[submodule "third-party/cuda-samples"]
path = third-party/cuda-samples
url = ./third-party/cuda-samples
[submodule "third-party/gpu-parboil"]
path = third-party/gpu-parboil
url = ./third-party/gpu-parboil
clone submodule¶
clone 时默认是不会 clone 子模块的,需要添加 recursive。-j8 表示使用多线程下载。
会从.gitmodules
中指定的 url 中 clone 仓库,然后 checkout 到对应 commit。如果是本地 commit,没有推送到远程,则会因为没有对应 commit 而报错。解决方法是改用本地仓库作为 url。
file not allowed 问题¶
Submodule 'third-party/cuda-samples' (/staff/fyyuan/repo/gpu-analysis-model/third-party/cuda-samples) registered for path 'third-party/cuda-samples'
Cloning into '/staff/fyyuan/repo/gpu-analysis-model-70/third-party/cuda-samples'...
fatal: transport 'file' not allowed
解决方法