惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Troy Hunt's Blog
Blog — PlanetScale
Blog — PlanetScale
Engineering at Meta
Engineering at Meta
F
Full Disclosure
Recorded Future
Recorded Future
The GitHub Blog
The GitHub Blog
Microsoft Security Blog
Microsoft Security Blog
GbyAI
GbyAI
博客园_首页
博客园 - 叶小钗
MongoDB | Blog
MongoDB | Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
H
Hacker News: Front Page
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
博客园 - 司徒正美
Webroot Blog
Webroot Blog
Google DeepMind News
Google DeepMind News
Help Net Security
Help Net Security
Cloudbric
Cloudbric
PCI Perspectives
PCI Perspectives
有赞技术团队
有赞技术团队
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
TaoSecurity Blog
TaoSecurity Blog
L
Lohrmann on Cybersecurity
量子位
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tailwind CSS Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
B
Blog RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
大猫的无限游戏
大猫的无限游戏
P
Proofpoint News Feed
N
News and Events Feed by Topic
罗磊的独立博客
T
Threat Research - Cisco Blogs
Schneier on Security
Schneier on Security
T
Tor Project blog
IT之家
IT之家
M
MIT News - Artificial intelligence
S
Security @ Cisco Blogs
O
OpenAI News
AI
AI
S
Securelist
Simon Willison's Weblog
Simon Willison's Weblog
The Last Watchdog
The Last Watchdog
月光博客
月光博客
Security Archives - TechRepublic
Security Archives - TechRepublic
L
LINUX DO - 热门话题

博客园 - 赵青青

AI模型Claude的Haiku、Sonnet、Opus 怎么选? obsidian(md笔记管理)使用实践 python中可变参数与装饰器的例子 C++ lambda 表达式 3ds max的obj文件格式说明 CPython调试和性能分析 Python3类型安全type hint Python3虚拟机和对象 vs编译cpp时设置排除项 与ChatGPT的对话在windows上获取mac地址 Python311新特性-特化指令specializing adaptive interpreter-typing-asyncio unity .net8 suppot comming pycharm一些减少代码warning的拼写检查设置 JavaScript速查表 Python cheatsheet 速查表 DirectX9(D3D9)游戏开发:高光时刻录制和共享纹理的踩坑 FFmpeg在游戏视频录制中的应用:画质与文件大小的综合比较 c++中字符串之string和char IMGUI快速入门
最小体积拉取git仓库并保持可更新
赵青青 · 2024-10-20 · via 博客园 - 赵青青

对于超大型的git 仓库不需要提交只是拉取代码进行查看并希望保持代码更新,那么使用depth不仅能得到极小体积的仓库还能大大提速拉取时间

拉取最小代码

结论:功德+1,来自于掌门的用法,depth设置为300之后,基本上没碰到问题,git新手也可以完整拉取。

拉取代码:git clone http://git-internal.nie.netease.com/xxx.git --depth=1 -b 分支名

原始仓库有10G+但通过上述方式拉下来的git仓库才311MB,为何这么小?

这是因为git clone --depth=1只会克隆一个分支最近一次的commit,这样这个项目文件就不会很大,缺点就是只能看到最近一次的log。

其他远程分支并不在本地,所以这种情况下,需要用如下方法拉取其他分支

$ git clone --depth 1 https://github.com/dogescript/xxxxxxx.git
$ git remote set-branches origin 'remote_branch_name'
$ git fetch --depth 1 origin remote_branch_name
$ git checkout remote_branch_name

depth=1 git pull无法拉取更新

在我本地使用git pull 无法拉取到新的修改,报错:fatal: refusing to merge unrelated histories,并且git fetch也无法拉取,完整的git log如下:

git.exe pull --progress -v --no-rebase --depth 1 "origin"
POST git-upload-pack (423 bytes)
POST git-upload-pack (434 bytes)
remote: Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
From http://git-internal.nie.netease.com/xxx
= [up to date]      分支名 -> origin/分支名
fatal: refusing to merge unrelated histories

这篇文章《加速几十倍 git clone 速度的 --depth 1,它的后遗症怎么解决? - 知乎 (zhihu.com)》,提到可以使用pull,但我本地却不行。

通过命令:git pull --rebase origin 分支名,就可以,但仍然是只有最后一次的提交log,最后修改depth的参数改大到300,就解决了。

长久未更新分支非常多冲突

我们有一个hotfix分支用来处理每周发版本后的更新,这个分支上有个文件每周都会被反复频繁修改然后在下个周期发版会被清空为空白文件。

重点来了:多周没更新之后在本地进行git pull或 fetch&rebase拉远程代码都会产生非常多冲突,每次都要花大量时间时间处理冲突

pull的选项不管怎么选,都无法成功,报错信息一般是:

  1. fatal: refusing to merge unrelated histories
  2. fatal: Not possible to fast-forward, aborting

image-20240924171418947

解决办法

解决办法如下:强制重置到远端分支的最新版本,操作步骤

  1. 使用pull进行拉取一遍(不要勾depth),尽管此时会pull失败,但能拉取远端最新的log,为后面做准备
  2. 在仓库中右键 show log
  3. 在log窗口的左上角点击分支名,切到远程分支最新日期的提交
  4. 回到log窗口,选中最新的提交记录,右键【reset 分支名 to this】,在reset窗口中选择【hard】进行完全重置

PS:碰到无法pull也可以使用此方法来解决

image-20240924165351039

扩展资料

tortoisegit选项 fast forward only和no fast forward是什么意思

在Git中,Fast-forward和No-fast-forward是两种不同的合并策略。

  1. Fast-forward(快进):如果当前分支没有新的提交,而待合并的分支有新的提交,那么Git会直接将当前分支指向待合并分支的最新提交。这种情况下,Git不会创建新的合并提交。这就像你快进电影到最新的场景,所以叫做"Fast-forward"。

  2. No-fast-forward(非快进):无论待合并的分支是否有新的提交,Git都会创建一个新的合并提交,并将当前分支指向这个新的合并提交。这样做的好处是,你可以清楚地看到项目的历史变化,知道何时进行了合并操作。

在TortoiseGit中,"Fast forward only"选项表示只进行快进合并,如果不能进行快进合并,那么操作会失败。"No fast forward"选项表示进行非快进合并,即使可以进行快进合并,Git也会创建一个新的合并提交。

其它方案拉取最小代码

git pull --rebase origin 分支名

git submodule update --remote

有兴趣的同学可以尝试