了解Visual Studio 2015的Git:恢复 [英] Understanding Git for Visual Studio 2015: Revert

查看:144
本文介绍了了解Visual Studio 2015的Git:恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于测试,我有一个简单的控制台应用程序,我承诺它(初始)。然后我添加一条评论并提交它(00)。然后我改变评论并提交它(01)



现在我想简单地回复到00.

 更改|操作|查看历史
右键单击00 |还原
您确定要还原.... |是

此时我遇到了一个冲突: Program.cs [both modified] 。但为什么会是冲突 - 我只想恢复到以前的版本?我点击它然后选择:

$ p $合并(按钮)
在来源上编辑|差分|采取源(链接)
编辑目标|差分| Take Source(links)

如果点击合并,我会看到三个不同的窗格(源,目标和合并)。



源代码看起来像我的第一个版本(初始),目标看起来像我当前的版本(01)合并看起来像我选择恢复到(00)。

如果我关闭该窗口,我会得到一个对话框,询问我是否想要接受合并结果 - 从那里我可以做到恢复与合并的文档。



你能解释源和目标面板的含义吗(看起来像目标是我当前的版本,但是在我想要的这个回归之前,源代码看起来像是一个版本(看起来像初始!)。

最终,我可以保留源面板,目标面板或合并的结果,基本上回到了这三种选择中的任何一种,这是VS 2015工具打算工作的方式吗?关键问题:如果我只想要r转换到以前版本的文件完全没有任何合并?

另外...我注意到,当我看到这个工具上的微软构建演示,他们做了回复,没有我上面讨论的问题。 https://channel9.msdn.com/Events/Build/2015/3-746 (见7:30标记)。



谢谢!



ps我没有找到关于如何恢复工具在互联网上的这个工具的文档,所以如果有一个请指出该链接,我会看看那里:)

解决方案

如果您选择一个要提交的提交,Visual Studio不会回复该时间点 - 它会逻辑删除提交的提交更改。它试图只删除在该提交中引入的更改。



考虑针对单个文件的一系列提交:



提交1



 第一行
第二行
第三行
第四行
第五行



提交2



 第一行
第二行
第三行
第四行
第五行



提交3



 第一行
第二行
第三行
第四行
第五行

如果你想恢复提交2 - 您试图撤销它所引入的更改,同时保留第3次提交中引入的更改。结果将为:
$ b

还原的提交2 第二行
第三行
第四行
第五行

然而,可能会有冲突。如果提交2改变了提交3发生更改的同一行,则回复会因为冲突而失败,您必须解决它才能继续。


For a test I have a simple console app and I commit it (Initial). Then I add a comment and commit it (00). Then I change the comment and commit it (01)

Now I want to simply revert back to 00.

Changes | Actions | View History
right-click 00 | Revert
Are you sure you want to revert .... | Yes

At this point I get a conflict: Program.cs [both modified]. But why would that be a conflict -- I just want to revert to the previous version?. I click that and then I have options to:

Merge (button)
Edited on Source | Diff | Take Source (links)
Edited on Target | Diff | Take Source (links)

If I click Merge I see three different panes, all with different versions (source, target, and merge).

The source looks like my first version (initial), the target looks like my current version (01) and the merge looks like what I have chosen to to revert to (00).

If I close that window I get a dialog that asks if I want to accept the merge results -- and from there I am able to do the revert with the merged document.

Can you explain what is meant by the source and target panels (it seems like the target is my current version, but the source looks like a version even before this reversion that I want (it looks like initial!).

Ultimately I can keep the source panel, the target panel or the results of the merge, essentially reverting to any of those three choices. Is this the way the VS 2015 tool is intended to work? Key question: what if I just want to revert to the previous version's file completely without any merging?

Also... I noticed when I watched the Microsoft Build Demo on this tool they did a revert and did not have the problem I discussed above. https://channel9.msdn.com/Events/Build/2015/3-746 (see at the 7:30 mark).

Thank you!

p.s. I did not find documentation for how revert works for this tool on the Internet so if there is one please point that link and I will look there :)

解决方案

If you select a commit to revert, Visual Studio does not "revert to" that point in time - it does a logical removal of the changes that commit introduced. It attempts to remove only the changes that were introduced in that commit.

Consider some series of commits for a single file:

Commit 1

Line one
Line two
Line three
Line four
Line five

Commit 2

Line one
Line 2
Line three
Line 4
Line five

Commit 3

Line ONE
Line 2
Line three
Line 4
Line FIVE

If you want to revert commit 2 - you are trying to undo the changes that it introduced, while retaining the changes introduced in commit 3. The results will be:

Reverted Commit 2

Line ONE
Line two
Line three
Line four
Line FIVE

However, there can be conflicts. If commit 2 had changed the same line that commit 3 had changed, the revert would fail with a conflict, and you would have to resolve it to continue.

这篇关于了解Visual Studio 2015的Git:恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆