- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我已经回顾了几个关于squashing the most recent commits的相关问题和 squashing a commit at the root ,但都不会帮助我压缩不在根目录下的非最近提交。
这是我的起始场景:
D---E---F---G---H---I---J master
和我想要的结果:
D---E---Z---I---J master
哪里Z
是F---G---H
的南瓜, 和 F---G---H
, D---E
, 和 I---J
可以是任意长的非分支提交序列。
第一种方法:
[lucas]/home/blah/$ git rebase -i D
rebase in progress; onto D
You are currently editing a commit while rebasing branch 'master' on 'D'.
No changes
You asked to amend the most recent commit, but doing so would make
it empty. You can repeat your command with --allow-empty, or you can
remove the commit entirely with "git reset HEAD^".
Could not apply F... "Comments from commit F"
[1]+ Done gitk
[lucas]/home/blah/$
我选择提交的地方 F---G---H
成为squash
,同时保留最旧的提交 - rebase 交互中的第一行 - 作为 pick
.为什么这行不通?
更新:在命令结束时,正在对 D
进行 rebase 与 E
作为 HEAD 提交。可以肯定的是,在开始和调用 git rebase --abort
时没有正在进行的 rebase 。再次运行时结果相同。当我根据上面的链接在 root 或 HEAD 执行此操作时,一切正常。
第二种方法:
我又做了一次尝试[通过 merge 一个新分支(论坛上的最后一个帖子)][ http://git.661346.n2.nabble.com/Non-interactive-squash-a-range-td5251049.html ) 使用 git checkout -b <clean-branch> <start-id> and
git merge --squash `,但我得到以下信息:
[lucas-ThinkPad-W520]/home/.../.Solstice_WS/7K_FGHF$ git checkout -b clean-branch D
Switched to branch 'clean-branch'
[lucas-ThinkPad-W520]/home/.../.Solstice_WS/7K_FGHF$ git merge --squash I
Updating D..I
Fast-forward
Squash commit -- not updating HEAD
.../GraphUtilities/impl/DAG.java | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
[lucas]/home/blah/$ git checkout master
error: Your local changes to the following files would be overwritten by checkout:
asdf/GraphUtilities//DAG.java
Please, commit your changes or stash them before you can switch branches.
Aborting
似乎有这样的结果:
------------------- <clean-branch> with non-committed changes
/
D---E---F---G---H---I---J <master>
我有点难过,那么我该如何压缩这些提交呢?
最终,我计划在 JGit
中实现它, 所以 JGit
实现也是可以接受的。
注意
可能有一个 duplicate here ,但它没有答案,我认为这个问题有点不清楚。
更新
这是对@ryenus 在下面的回答的回应:
cherry-pick 在提交时失败 I2
, 其中I2
在I---I2---J
.当它失败时,我的 work
的状态分支机构有D---E---Z
,按照预期进行,直到选择为止,然后是未提交的更改。打电话git cherry-pick --abort
清除这些未提交的更改,我验证了提交 Z
是对的,就是F---G---H
的南瓜.提交后Z
, 然后 cherry-picking,为什么 cherry-pick 在 F
失败?
好像git cherry-pick I...J
正在尝试挑选 I2
,这会造成 merge 冲突并失败。有什么建议吗?
这是我的输出:
[lucas]/home$ git checkout -b work H
Switched to a new branch 'work'
[lucas]/home$ git reset E
Unstaged changes after reset:
M adf/GraphUtilities//graph/impl/DAG.java
[lucas]/home$ git commit -am "squashed commit here!"
[work Z] squashed commit here!
1 file changed, 2 insertions(+), 5 deletions(-)
[lucas]/home$ git cherry-pick I...J
error: could not apply I2... <Comments from commit I2>
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
[lucas]/home/$ git status
On branch work
You are currently cherry-picking commit I2.
(fix conflicts and run "git cherry-pick --continue")
(use "git cherry-pick --abort" to cancel the cherry-pick operation)
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: 3b6863741967406c1888701eb139178187d429487b99787096441d67bed56/Gra
phUtilities/src/edu/washington/cs/utils/graph/impl/DAG.java
no changes added to commit (use "git add" and/or "git commit -a")
[lucas]/home$
最佳答案
首先,如果 F---G---H
被压扁,那么 I---J
将是 I'--- J'
.
鉴于此,我会先创建一个分支,然后使用 vanilla git reset
然后是 git cherry-pick
:
# D---E---F---G---H---I---J master
git checkout -b work H
在 H
work
git reset E
现在工作
在E
git commit -am "F-G-H 压缩为 Z"
将 F---G---H
所做的更改提交为 Z
git cherry-pick I^..J
接管I---J
现在 work
分支处于您想要的状态,只需将 master
重置为它:
# D---E---Z---I`---J` work
git checkout master
git reset work
git branch -d work
注意:提交范围已更正为I^..J
,代表提交系列I---J
(来自I
code> 到 J
,包括在内)。
关于Git:压缩不是最近提交的连续提交,并且不从根开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26029698/
我需要获取过去 24 小时的记录,但不能像这样按小时分组: SELECT HOUR(CompDate) AS hour, COUNT(1) AS action FROM mytable WHERE (
我们有一个自动完成列表,当您向某人发送电子邮件时会填充该列表,这一切都很好,直到列表变得非常大,您需要输入越来越多的地址才能找到您想要的地址, 这违背了自动完成的目的 我在想应该添加一些逻辑,以便自动
我在 android 的锁屏上工作我们如何禁用导航软按钮,已经尝试了所有方法,systemoverlay但它不起作用,在按下主页按钮时它会终止服务和 Activity 。 最佳答案 后退按钮可以通过覆
我有一个报告创建时间为 2016-05-30,现在我需要从报告时间开始的最后 7 天。我怎样才能使用时刻? report_create_time = moment('2016-05-30').form
我想找出向量中最接近的三个数字。 就像是 v = c(10,23,25,26,38,50) c = findClosest(v,3) c 23 25 26 我试过 sort(colSums(as.ma
考虑以下表结构: id speed 1 100 2 200 3 300 4 400 5 500 考虑以下查询:"SELECT * FROM records WHERE
我正在开发一个依赖 YouTube 直播和实时聊天(也来自 YouTube)的网络应用。事情进展顺利,突然嵌入的聊天功能无法在移动设备上运行。 我试图在我这边找到一个错误或一些无效的配置,但我找不到。
我正在制作一个 React Native 应用程序,它有一个安全部分,用户必须在其中输入密码才能解锁 protected 内容。问题是,当用户在锁定该部分之前切换到另一个应用程序时,将生成屏幕截图以及
我有一条 SQL 语句 (SQL Server Management Studio),我通过仪表板软件将数据传递到 where 语句中。用户可以选择年份(2013 年或现在的 2014 年)和月份(作
我有一个脚本可以添加一组行,使您能够在 SharePoint 列表表单中捕获其他访问者的信息。我有两个 anchor 标记,一个用于添加,另一个用于删除。当我添加一个新的访问者时它有效,当我删除访问者
我正在学习斯坦福 iOS 类(class),我有一个问题,我认为与最近的更新有关。这是代码部分: func evaluate(ops: [Op]) -> (result: Double?,remain
我注意到我的应用有一个奇怪的行为。每当我按下主页按钮时,我的应用程序就会被杀死。我没有在应用程序堆栈中看到该应用程序。我可以看到之前启动的其他应用程序。最初我怀疑 android:launchMode
我需要获取过去 7 天内的所有付费和临时条目,但我总是收到所有退回的内容。我不确定我做错了什么,我已经阅读了这里的很多帖子,但无法理解它是什么。 MySQL 5.6(如果它与我一直在做的事情有什么不同
我的表有一列以 mysql time() 格式格式化。 当它是一个值分配给名为 $preRemainOt 的 php 变量时我想重新安排到最近的 15 分钟 function roundTime($w
我想获取过去 7 天内每天每个产品的最后时间戳。数据库中有数千条记录。我怎样才能通过查询来做到这一点。大约有 25 种不同的产品,每种产品每天大约有 50 个时间戳。 表:构建数据 'Timesta
我现在的代码正在从 SQL 中获取移动应用程序中的数据,首先添加显示,我需要将其设置为在我的 Android 应用程序中显示最后添加的第一个。我有如下所示的 api 代码,最新的是根据我的要求显示的,
我有一张 table ,说 table 的描述为: | ID | SNO | c1 | c2 | c3 | ___________________________________ |
我有两个大小相等的向量,例如 A=[2.29 2.56 2.77 2.90 2.05] and B=[2.34 2.62 2.67 2.44 2.52]. 我有兴趣在两个相同大小的向量 A 和 B 中
之前,我在这里发布了一个问题,询问有关如何从驱动器读取和写入数据的建议,而不是通过像“aaa.txt”这样的文件标签,而只是扇区..我被建议尝试阅读和写作....但新问题出现了……毛茸茸的参数 int
我想删除在给定时间段内未登录的用户,但我稍后会根据结果选择时间段。 所以我需要报告,其中我将收到过去 1 个月、2 个月...... n 个月内未登录的用户数量。 我不太清楚如何在单个 mysql 查
我是一名优秀的程序员,十分优秀!