Git
2023-04-26
开源中国文章 紧跟 AI 步伐, Gitee 已支持 AI 模型托管 中介绍了 Git LFS 的使用。
结合 git lfs help,记录如下:
-
需要先 install 一下,启用 LFS 功能
$ git lfs install
Updated Git hooks.
Git LFS initialized.
-
追踪大文件
git lfs trace path/to/largefile
# 会记录在 .gitattributes 文件中
# path/to/largefile filter=lfs diff=lfs merge=lfs -text
-
推送大文件
# 正常提交
git add .gitattributes path/to/largefile
git commit -m "..."
# 推送
git lfs push --all
git lfs push --all origin
-
拉取大文件
git lfs pull --all
# 指定文件
git lfs pull -I <filepath>
-
git lfs ls-files
列出大文件
Git
2023-03-13
看到一篇公众号文章 《Git仓库迁移实操(附批量迁移脚本)》,介绍他们将 GitLab 中一个 Group 内的几十个项目迁移到另一个 Group。
PS:文章有提到,前提是无法得到管理员协助,开启创建时导入的功能。
git clone
& git push
&& git push --tags
git clone --mirror
&& git push --mirror
git clone --bare
&& git push --mirror
基本方法就是 clone && push,不过参数不同。
只是,我没有了解过这里说的 --mirror
参数,这里记录一下,用到的时候研究研究。
文章带了两个脚本:
-
Linux migrate.sh
#!/bin/bash
remote_old=git@host1:group1
remote_new=git@host2:group2
while read repo
do
echo $repo
git clone --bare "$remote_old/${repo}.git"
cd "${repo}.git"
git push --mirror "$remote_new/${repo}.git"
cd ..
rm -fr "${repo}.git"
done < repos.txt
-
Windows migrate.bat
@echo off
set remote_old=git@host1:group1
set remote_new=git@host2:group2
set input_file=repos.txt
SETLOCAL DisableDelayedExpansion
FOR /F "usebackq delims=" %%a in (`"findstr /n ^^ %input_file%"`) do (
call :process %%a
)
goto :eof
:process
SETLOCAL EnableDelayedExpansion
set "repo=!%1!"
set "repo=!repo:*:=!"
echo !repo!
git clone --bare "%remote_old%/!repo!.git"
cd "!repo!.git"
git push --mirror "%remote_new%/!repo!.git"
cd ..
rmdir "!repo!.git"
ENDLOCAL
goto :eof
Git
2023-01-10
Git 开发工具
2022-01-17
读到微信公众号文章 本地如何配置多个 GitHub/Gitee 账号?,想起了几年前,面对这样的需求,我自己也是这么操作的。
Git 开发工具 版本管理
2021-08-04
看到有篇文章说是 git “新增”了 switch 和 restore 两个命令,仔细一看,原来就是 2019 年就引入了的两个命令,不过我确实没有用过。
这里重新整理一下现在 git 的命令。
git version
git version 2.30.2
apt list --installed | grep ^git
git-doc/hirsute,hirsute,now 1:2.30.2-1ubuntu1 all [已安装]
git-extras/hirsute,hirsute,now 6.1.0-1 all [已安装]
git-flow/hirsute,hirsute,now 1.12.3-1 all [已安装]
git-man/hirsute,hirsute,now 1:2.30.2-1ubuntu1 all [已安装,自动]
git-svn/hirsute,hirsute,now 1:2.30.2-1ubuntu1 all [已安装]
git/hirsute,now 1:2.30.2-1ubuntu1 amd64 [已安装]
gitg/hirsute,now 3.32.1-1 amd64 [已安装]
gitk/hirsute,hirsute,now 1:2.30.2-1ubuntu1 all [已安装]
Git
2021-07-05
今天注意到了 git push 的一个参数 --force-with-lease
,可以在 Remote 有更新的时候不执行强推。
我之前考虑过会有这样的情况发生:我准备强推之前,会做最后一次拉代码检查,无误之后 force push。但是这个检查和 push 之间有一个时间差,会不会在这期间有别的小可爱提交了代码呢?
这种情况是完全可能存在的,就像是线程安全问题,只是团队的规模消减了我对这种情况的担心。
但是 --force-with-lease
参数可以彻底化解我的这种担忧,我决定以后就改用这个参数了。
Git 项目管理
2021-04-07
Git
2020-06-12
搜索提交信息
git log --grep=fix: --oneline --after='2018-07-01' --author=catroll
搜索历史文件
git grep -C3 sign_position $(git rev-list --all)
搜索 diff 内容
git log -G'前置'
git log -G'前置' -p | grep '前置' -C5
git log -G'前置' --oneline --name-status
-S<string> --pickaxe-regex
和 -G<regex>
作用相近,
不过 -S
只会列出搜索内容增删的相关信息,也就是所在行修改了,但是搜索内容没有变化的会忽略
Git Windows
2020-03-22
Git
2020-02-24
开发工具 Git
2019-08-01
git log --diff-filter=A --follow --format="%h %ad %ce" -1 -- requirements.txt | cat
# 6a0eebf 2019-05-22 19-47-09 bobo@example.com
参考:https://stackoverflow.com/questions/2390199/finding-the-date-time-a-file-was-first-added-to-a-git-repository
Git
2019-01-03
Git 开发工具 版本管理
2018-08-01
git diff
对应 diff
命令
git apply
对应 patch
命令
git diff v1.2.1 v1.2.2 > v1.2.1_v1.2.2.patch
git apply --check v1.2.1_v1.2.2.patch
git apply -v --whitespace=warn v1.2.1_v1.2.2.patch
有部分文档中说 git apply
和 patch
在一些细节上实现不一致,需要留意。但我轻量级使用,没有遇到过什么问题。
Git
2017-12-07
Git 开发工具
2017-03-15
有时需要临时分享一个仓库给朋友,我们可以用 SSH 协议:
git clone ssh://catroll@192.168.64.234/home/catroll/Projects/catroll/lego
其实 git-daemon 是一个更好的方法。