Visual Studio 还原Git中的更改并保留以后的更改集

nfs0ujit  于 2022-12-04  发布在  Git
关注(0)|答案(1)|浏览(288)

I'm unsure if I wrongly understood how the revert works or is it Visual Studio just doing something weird. Firstly I made the following commit inside of master branch

WriteNumbers(100, 2);

void WriteNumbers(int toWhere, int dividableByWhat)
{
    for (int i = 1; i <= toWhere; i++)
        if (i % dividableByWhat == 0)
            Console.WriteLine(i);
    Console.WriteLine();
}

Then I created new branch, switched to it and just added the new line as follows

WriteNumbers(100, 2);
WriteNumbers(100, 3);

void WriteNumbers(int toWhere, int dividableByWhat)
{
    for (int i = 1; i <= toWhere; i++)
        if (i % dividableByWhat == 0)
            Console.WriteLine(i);
    Console.WriteLine();
}

I merged this branch into master. Afterwards I made another commit in master where I just added a new WriteNumbers(100, 4); line.
Now from my understanding If I revert the changeset which introduced WriteNumbers(100, 3); I should still have WriteNumbers(100, 4); in my file but that just doesn't seem to be case, at least in Visual Studio.

As it can be seen when I run revert on changeset, I get option to either delete both lines (as was before I merged the second branch into master) or to keep both changes (which is also invalid state). Is there any other way to just delete WriteNumbers(100, 3); line or I'm just doing something wrongly?

gwbalxhn

gwbalxhn1#

当您还原的提交更改了在以后的提交中被更改的行(或其周围的行被更改)时,您会得到一个 * 合并冲突 *。您必须手动解决此冲突,这也是Visual Studio要求您做的。
Git和Visual Studio都无法知道哪些行在还原后是正确的,所以你必须选择。

相关问题