Understanding Git for Visual Studio 2015: Revert

后端 未结 1 994
暖寄归人
暖寄归人 2021-02-09 23:13

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 sim

相关标签:
1条回答
  • 2021-02-09 23:56

    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.

    0 讨论(0)
提交回复
热议问题