- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有 2 个分支:master 和 feature。
• master
• feature
我在功能分支上做了两次提交
• master
• C1 • C2 • feature
现在,我想 merge master 中的 feature
。我使用 git merge --squash feature
来 merge 。
• C3 • master // C3 is the squashed commit
• C1 • C2 • feature
此时,有没有办法从 master 恢复 C1
?
一个选项是恢复 C1
功能,并在 master 中再次压缩 merge 功能。
最佳答案
是的,您可以使用 merge --squash
恢复一些提交,即使它已包含在聚合中。 git-revert
的工作原理是识别在您识别的提交中引入的更改,然后创建一个新的更改来撤消(“还原”)这些更改。
它使用三向 merge 算法来执行此操作 - 使用要还原的提交作为基础,然后与该提交的祖先和当前提交 (HEAD
) 进行比较。这将隔离仅在该提交中引入的更改。
看一个非常人为的例子,想象一下你有一个文件有三个变化(C0
、C1
和 C2
)和这些是每个版本的文件内容:
| C0 | C1 | C2 |
|-------|-------|-------|
| one | one | one |
| two | 2 | 2 |
| three | three | three |
| four | four | FOUR |
现在,如果你想还原C1
,我们设置一个三向 merge 以它为基础,C0
和C2
每一方都要从中进行更改。
在三向 merge 算法中,您会查看每一侧,并将其与底部进行比较。如果所有三行都相等,则将该行原封不动地放入结果中。如果一方进行了更改,则将更改后的行带入结果。 (如果双方都对同一行进行了更改,则将该行标记为冲突。)
设置还原为您提供:
base sides result
---- ----- ------
one
/ two \
/ three \
one / four \ one
2 two
three three
four \ one / FOUR
\ 2 /
\ three /
FOUR
您可以看到结果(在右侧)撤消 C1
中引入的更改,因为其中一侧 (C0
,在本例中)是唯一的,因此其更改保留在结果中。这具有撤消(“还原”)其中引入的更改的逻辑效果。
This would be true even if you had done a squash merge - in this case, it's looking at the repository's contents. It doesn't matter that
CM
doesn't actually haveC1
as a common ancestor.
您可以在包含这些内容的简单存储库中向自己证明这一点。即使在 Squash merge 之后:
commit 9e7497c7ae34aa35cdb7d7b965a00d56bf0b9dfa
Author: Edward Thomson <ethomson@edwardthomson.com>
Date: Thu Nov 9 10:20:31 2017 +0000
Squashed commit of the following:
commit 8a8a9e73e62e21683e15269d89e1fbfbbf35cfa1
Author: Edward Thomson <ethomson@edwardthomson.com>
Date: Thu Nov 9 10:20:18 2017 +0000
C2
commit d984b27140e48c5faa8968364c415d29dcd7034c
Author: Edward Thomson <ethomson@edwardthomson.com>
Date: Thu Nov 9 10:20:08 2017 +0000
C1
您仍然可以正确还原其中一个组件。在这种情况下,我将还原 C1
:
> git revert d984b27
[master 405f108] Revert "C1"
1 file changed, 1 insertion(+), 1 deletion(-)
> git show HEAD
commit 405f1080e24504fa418d423a0755a2123b85ecd8 (HEAD -> master)
Author: Edward Thomson <ethomson@edwardthomson.com>
Date: Thu Nov 9 10:20:42 2017 +0000
Revert "C1"
This reverts commit d984b27140e48c5faa8968364c415d29dcd7034c.
diff --git a/hello.txt b/hello.txt
index 9d980ae..14cf0bc 100644
--- a/hello.txt
+++ b/hello.txt
@@ -1,5 +1,5 @@
Hello, world!
one
-2
+two
three
four
关于git - 恢复不在当前分支中的 git 提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47197215/
假设我有一个带有隐藏提交按钮的表单,我在其中输入值,然后我点击一个按钮,就会出现带有确认消息和确认按钮的对话框。当我单击“确认”按钮时,我还单击了表单中隐藏的提交按钮。这可能吗?我如何在 JQuery
我们正在学习 Git 并使用 GitHub 作为我们的托管站点。 我们都 fork upstream repo 并 PR 我们的提交到 upstream 以获取我们的更改。 我们正在努力学习如何压缩我
我只需要一些关于这段代码的帮助。 var prv3; var markIt3 = function(e) { if (prv3 === this && this.checked) { th
如果 1 个表单使用“GET”方法而另一个使用“POST”方法,我如何提交位于同一页面上的 2 个表单。每个表单都有相同的操作并转到相同的下一页。需要帮忙。感谢大家的帮助。 我怎样才能得到下面这两个使
您好,我的表单中有以下脚本 function pdf() { var frm = document.getElementById("form1"); frm.action = "http://www.
我有一个 iOS 胖静态库(iphoneos 和 iphonesimulator),如果我在应用程序提交期间使用它,它会因为二进制文件包含 iphonesimulator 代码而失败吗? 最佳答案 我
我似乎有一个卡住的 git repo。它卡在所有基本的添加、提交命令上,git push 返回所有内容为最新的。 从其他帖子我已经完成了 git gc 和 git fsck/ 我认为基本的调试步骤是
我正在尝试发送由 jquery 创建的表单。该表单附加到一个 div 中,下面的变量“data”是使用 php 创建的,我将只发布最重要的 js 代码。 我尝试了很多带有和不带有“on()”的操作,但
我面临一个简单的问题,但不知道如何解决。我正在使用 twitter bootstrap 的标签。选项卡有效,但每个选项卡中的表单不提交。表单在没有选项卡的情况下提交。 以下是我用于标签的链接
我的计算机上有 140 个 git 存储库,每周我可以处理其中 10-15 个。有没有办法知道是否忘记提交/推送我的一个项目? 这些存储库都位于同一位置:“C:/Projects”。 输出类似于 C:
我对 javascript 完全陌生,目前正在开发我的第一个函数。我有这 2 个文本输入区域,可以在其中输入他的姓名和级别。 Nom: Niveau (1 á 6): 提交后,
我安装了最新的 Docker CS,得到了 LAMP image来自 Docker 集线器。我正在尝试在其中创建一个数据库并使用保存在其中的数据库制作一个新图像。 启动容器:docker run --
我有这个 jQuery 简单代码: 由于某种原因,submit() 无法正常工作(我的表单在单击 old_thumb 按钮后未提交。有人可以帮助我吗? 这里是 html 的一部分(它很长
如何获得 input type="submit"onclick 事件来触发 commitfunds.valdiate?我不能使用类或 ID。它必须是一个 onclick 事件。 这是代码: row A
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
来自 this earlier thread我以为我知道可以使用 javascript submit() 命令通过 POST 方法发送表单数据。但我无法让它工作。这个演示在目的方面没有明显的意义,但请
在 mysql 重新启动时提交 XA 待处理事务时,出现以下错误。请帮助我解决这个错误。 mysql> XA RECOVER CONVERT XID; +----------+------------
我有一个带有 的表单. 如果启用了 Javascript,我将删除此 submit -输入字段$('#no-js-submit').remove();并添加“fire-ajax”按钮 $('Fire
我希望在页面加载后提交此表单,并且我使用了以下代码来完成此操作。问题是页面不断重新加载并停留在该循环中。 HTML Select Genre
我们有一个表单,其中有几个单独的提交按钮,它们执行不同的操作。问题是我有几个具有以下 HTML 的按钮: 现在您无法使用标准的 find_control 函数按值定位元素。所以我写了一个谓词函数来
我是一名优秀的程序员,十分优秀!