Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding Git for Visual Studio 2015: Revert

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 :)

like image 404
Matt M. Avatar asked Oct 19 '15 19:10

Matt M.


People also ask

What is revert in git Visual Studio?

Use the revert command to undo the changes made in commits pushed to shared branches. The revert command creates a new commit that undoes the changes made on a previous commit. The revert command doesn't rewrite the repository history, which makes it safe to use when you're working with others.

How do I revert to a previous version of git in Visual Studio?

To revert changes made to a file in the working directory, just choose "revert changes" from the context menu in Visual Studio. Save this answer.

What is git revert example?

The purpose of the git revert command is to remove all the changes a single commit made to your source code repository. For example, if a past commit added a file named index.html to the repo, a git revert on that commit will remove the index.html file from the repo.

How do I revert changes to git?

First, you'll need to find the ID of the revision you want to see. This assumes that you're developing on the default main branch. Once you're back in the main branch, you can use either git revert or git reset to undo any undesired changes.


1 Answers

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.

like image 169
Edward Thomson Avatar answered Sep 17 '22 13:09

Edward Thomson