- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我昨天 merge 了两个分支。在 merge 过程中,我不小心 stash 了一些更改,同时解决了 merge 冲突。
我刚刚意识到现在 Git/SourceTree 没有将 merge 提交显示为 merge ,因为它没有指向 merge 提交的图形链接/行。
我不确定这是怎么发生的,是否是由于上述 stash 或代表我的其他一些错误。
自 merge 以来,我已经付出了一些努力来修复构建错误等,所以我不想重新启动。
所以我的问题是:有什么方法可以解决这个问题吗?!
最佳答案
如果您的查看器准确地向您显示了提交,并且没有将其显示为 merge 提交,那么它确实不是 merge 提交。
以相反的顺序(很像 Git):
So my question is: Is there some way to fix this?!
是的。如有必要,通过提交保存所需的 merge 后结果。保存任何其他必要的东西(例如,根据需要进行额外的提交)。我们这样做是因为提交大多是永久性的,也就是说,我们将能够取回它们。
然后,使用 git reset --hard <hash>
将当前分支名称移回一切出错之前的位置,然后重复 merge 。使用保存的结果设置所需的 merge 结果,并提交。如果需要,继续复制其他提交(使用 git cherry-pick
)。请参阅下面的示例(在“恢复”部分下)。
I merged two branches yesterday. During merging I accidentally stashed some changes, while resolving merge conflicts.
这应该是不可能的——除非,也就是说,您将所有文件都标记为已解决。为了演示,我设置了一个 merge 冲突并运行了 git stash
:
$ git merge sidebr
Auto-merging file
CONFLICT (content): Merge conflict in file
Automatic merge failed; fix conflicts and then commit the result.
[elf.24] T> git status
On branch master
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: file
no changes added to commit (use "git add" and/or "git commit -a")
$ git stash
file: needs merge
file: needs merge
file: unmerged (3b0f0fbe60a4e91d6bc2b714ecaf6b7626067fbb)
file: unmerged (94101158b0ecff92a135ff928f9497c9d8ac8c16)
file: unmerged (70f0a490221b56a23f0879634b84cb6b1f9166c5)
fatal: git-write-tree: error building trees
Cannot save the current index state
$
冲突文件如下,仅供引用:
$ cat file
file for making a merge conflict
<<<<<<< HEAD
this is the second line
||||||| merged common ancestors
line 2
=======
line two
>>>>>>> sidebr
让我们将其标记为已解决(同时将所有冲突标记留在其中)并 stash 起来,看看这是否会破坏我们的 merge 状态:
$ git add file
$ git status
On branch master
All conflicts fixed but you are still merging.
(use "git commit" to conclude merge)
Changes to be committed:
modified: file
$ git stash
Saved working directory and index state WIP on master: 33773a5 conflicting change on master
$ git status
On branch master
nothing to commit, working tree clean
确实,进行两次 stash 提交并执行 git reset
(git stash
所做的) 破坏了 merge 状态。应用和删除存储不会恢复 merge 状态:
$ git stash apply
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: file
no changes added to commit (use "git add" and/or "git commit -a")
$ git stash drop
Dropped refs/stash@{0} (187eaa6e372592f697ea7f0dc43056aadb8b7a18)
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: file
no changes added to commit (use "git add" and/or "git commit -a")
现在,从未提交的 merge 向前开始,一切都出错了。让我们快速浏览一下我们现在有什么(您可以使用您喜欢的查看器,只要它显示足够多):
$ git log --all --decorate --oneline --graph
* 33773a5 (HEAD -> master) conflicting change on master
| * c46f563 (sidebr) conflicting-change-on-sidebr
|/
* f23af46 mergebase
* d588ca0 initial
我们刚刚看到我们还没有提交“好”的最终 merge 结果(它不是很好所以让我们放一个演示版本),所以我们现在应该提交:
$ cat << end > file
> file for making a merge conflict
> which is now resolved
> end
$ git add file
$ git commit -m merged-but-not-merged
[master ba3208a] merged-but-not-merged
Date: Fri Jan 12 07:38:16 2018 -0800
1 file changed, 1 insertion(+), 1 deletion(-)
$ git show
commit ba3208a75c3f4132d32b2d258fc8d4f1582e5837 (HEAD -> master)
Author: Chris Torek <chris.torek@gmail.com>
Date: Fri Jan 12 07:38:16 2018 -0800
merged-but-not-merged
diff --git a/file b/file
index 9410115..14e570a 100644
--- a/file
+++ b/file
@@ -1,2 +1,2 @@
file for making a merge conflict
-this is the second line
+which is now resolved
解析数据的哈希 ID 是 ba3208a75c3f4132d32b2d258fc8d4f1582e5837
— 简短版本也足够了 — 一切都很干净:
# help from A DOG: All Decorate Oneline Graph
$ git log --all --decorate --oneline --graph
* ba3208a (HEAD -> master) merged-but-not-merged
* 33773a5 conflicting change on master
| * c46f563 (sidebr) conflicting-change-on-sidebr
|/
* f23af46 mergebase
* d588ca0 initial
$ git status
On branch master
nothing to commit, working tree clean
我们现在准备使用git reset --hard
,这将似乎 丢失我们所有的工作,但实际上这些提交仍在 Git 中,由它们的 reflog 条目保存(使用 git reflog
查看它们)并且我们已经记下或复制到另一个窗口, key 哈希 ID:
$ git reset --hard 33773a5
HEAD is now at 33773a5 conflicting change on master
$ git log --all --decorate --oneline --graph
* 33773a5 (HEAD -> master) conflicting change on master
| * c46f563 (sidebr) conflicting-change-on-sidebr
|/
* f23af46 mergebase
* d588ca0 initial
现在我们准备重新进行 merge ,这次是正确的:
$ git merge sidebr
Auto-merging file
CONFLICT (content): Merge conflict in file
Automatic merge failed; fix conflicts and then commit the result.
“好的结果”在我们保存其 ID 的提交中,所以提取它们。您可以使用 git checkout <hash> -- .
只要你在树的顶层,这个命令就更容易记住,尽管我会使用 git read-tree --reset -u
,这也避免了通过删除解决的文件偶尔出现的棘手问题:
$ git read-tree --reset -u ba3208a # or git checkout ba3208a -- .
$ git status
On branch master
All conflicts fixed but you are still merging.
(use "git commit" to conclude merge)
Changes to be committed:
modified: file
$ git commit
此时,您选择的编辑器出现,这样您就可以构建比默认编辑器更好的 merge 消息,但我保留默认编辑器并退出编辑器:
[master e097ef5] Merge branch 'sidebr'
$ git log --all --decorate --oneline --graph
* e097ef5 (HEAD -> master) Merge branch 'sidebr'
|\
| * c46f563 (sidebr) conflicting-change-on-sidebr
* | 33773a5 conflicting change on master
|/
* f23af46 mergebase
* d588ca0 initial
$ cat file
file for making a merge conflict
which is now resolved
所以我们到这里就完成了,除非您有额外的提交,在这种情况下您现在可以使用 git cherry-pick
在新 merge 后将它们复制到位(在我的例子中,新 merge 具有短哈希 ID e097ef5
但你的当然会有所不同)。
关于Git merge 提交未在 Git/SourceTree 中显示为 merge ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48223068/
我的存储库去了哪里?它们在 Sourcetree 的左侧,现在它是空白的,我不知道如何找到它们。看截图: 最佳答案 版本 2.0+ 书签已更改为本地存储库文件夹并被视为选项卡。 单击选项卡旁边的 +
我正在删除源树上的帐户,但是每当我尝试删除时: Tools > Options > Authentication SourceTree不会删除保存的密码。我需要删除密码,因为它包含与帐户关联的错误详细
我想提交我的作品。但是当我想查看我更改的内容并将它们写入提交消息时,我看到我的一些更改不会显示。 问题是什么? 最佳答案 更改选项中的最大行数和大小 工具 > 选项 > 差异 更改最大差异线数 和 更
我将 SourceTree 与 TortoiseDiff/Merge 一起使用。每次我在那里保存文件时,在解决所有冲突后,SourceTree 都会完美地处理一切,除了它总是创建一个备份文件 [nam
最近我重新安装了 macOS。我已经安装了 Sourctree 和 diffmerge 并将 diffmerge 设置为默认合并工具。出于某种原因,每次当我选择“解决冲突 - > 打开外部合并工具”时
从版本 3.3.6.3829 开始,必须通过按 F5 手动更新 sourcetree 中的 View 。我试图在 https://jira.atlassian.com/ 上将此作为错误提出,但该表单没
我想在 SourceTree 中设置默认文件查看器。当前的是记事本,它没有正确显示换行符(所有代码都在一行中)。 最佳答案 SourceTree 使用默认的“打开方式”应用程序,如资源管理器。据我所知
我的公司坚持使用 Sourcetree,我正在努力找出如何创建组并在这些组中包含分支,因为 ORIGIN 变得凌乱,正如您在此处看到的,列表是显示的项目的 3 倍以上这个截图。我尝试在软件本身中寻找一
我正在使用 SourceTree (mac)。 我有一些隐藏的更改。 我如何为每个 stash 指定一个自定义名称以更好地识别代码应该做什么? 现在,当我藏匿它时,它会在表单中获得一个自动名称 [分支
我有一个文件夹,其中有几十个子文件夹,每个子文件夹都有自己的项目,使用 git 进行版本控制,如下所示: 项目: 项目_a 项目_b ... project_z 我想将它们全部添加到某个文件夹的 So
在 Windows 8 上并尝试使用 SourceTree 作为我的 Git 客户端 - 一切正常,但以下内容: 当我点击 Sourctree 中的终端按钮时,它显示“无法启动 Git Bash 终端
我尝试从 sourcetree 打开一个 javascript 文件,但它试图执行它而不是在我的编辑器中打开脚本: 有没有办法改变这种行为? 最佳答案 我找到了解决方法。在某处创建一个 javascr
出于好奇,当我使用这些工具只是为了与私有(private)网络中的 repo 同步时。 虽然 GitKraken 要求 GitHub 登录,但我的代码隐私是否受到保护。 谢谢, 最佳答案 我知道有点晚
我尝试从 sourcetree 打开一个 javascript 文件,但它试图执行它而不是在我的编辑器中打开脚本: 有没有办法改变这种行为? 最佳答案 我找到了解决方法。在某处创建一个 javascr
带有 Windows 10 的 Sourcetree 3.3.6 不更新 UI 内容或不刷新 View 。 如果您想查看更新的 View ,则需要重新启动应用程序。 有什么解决办法吗? 最佳答案 在获
嘿,我刚刚将 Mac 上的 Sourcetree 更新到最新版本 (2.2)。git-flow 去哪儿了? 如何重新启用此功能? 没有它我就迷失了自己! 最佳答案 我这里也有同样的问题,你仍然可以使用
我真的很高兴 SourceTree 嵌入了 Mercurial。在奇怪的情况下,我想从 CLI 运行 hg 命令,例如 hg status 我得到的内容 hg: command not found 我
我的问题 在我当前正在处理的项目中,我无法使用 SourceTree 初始化 gitflow。你能帮忙吗? 我的 SourceTree 版本是 2.7.6。 屏幕截图 如果我尝试这样做 然后我有这个对
我想在 SourceTree 中显示 Gravatar 图像。我的 github 提交使用这个电子邮件地址:mboom@users.noreply.github.com。我已经为主要电子邮件设置了一个
默认情况下,SourceTree 2.x 静默安装并选择坐在 C:\Users\\AppData\Local\SourceTree目录。 彻底移动它不会破坏它,但更新程序无法正常工作 - 仍然在旧位置
我是一名优秀的程序员,十分优秀!