git - 如何从最新提交创建分支
问题描述
最近我遇到了一个独特的问题,我必须在一个分支中只包含最新的提交,而丢弃所有旧的。
例如考虑我有这样一个提交结构:
[main branch]
af474e3 (HEAD -> main) Updated modal UI
c0f9599 Added modal UI <-- This commit onwards is what our requirement is
e50c805 Updated button UI
de2ab3c Added button UI
9b1822f Initial commit
(我知道这听起来很傻,但是,)我想从那时起获取所有(最新的)提交以及与之相关的所有提交信息,即提交日期、提交作者等。
创建的分支必须如下所示:
[new branch]
af474e3 (HEAD -> new, master) Updated modal UI
c0f9599 Added modal UI
我试过removing/squashing commits with interactive rebasing
了,没用。
Cherry-picking
也没有用。
这可以实现吗?有没有简单的方法来实现这一目标?
解决方案
您希望分支以具有类似修订c0f9599
的文件和内容的修订开始吗?
git checkout --orphan new-branch c0f9599
git commit -C c0f9599 # use the same comment as c0f9599
git cherry-pick af474e3
给你!(当然,修订 ID 会有所不同)
推荐阅读
- java - SpringBoot Application Junit 测试无法自动装配
- python - 当我尝试抓取一些 URL 时,它返回“无表”
- reactjs - 试图弄清楚如何在 Gatsby.js 中实现 cookie 并以某种方式使用新的 GDPR 法来管理它们
- c# - 使用 MVVM 模式在页面上导航的 WPF 页面
- r - 如何将多行拉入列?
- android - TF2.0 lite for Android : 将 Keras (LSTM) 模型转换为 tflite
- python - 在散点图中显示方向箭头
- r - 在多个模糊匹配上合并 2 个 data.tables
- styled-components - Emotions.js 或 Styled-components ThemeProvider 提供什么?
- hiveql - 如何复制 Hive 分区表