Git在Visual Studio 2019和Android Studio 3.5.3中的”Revert”之间有什么区别?

huangapple go评论83阅读模式
英文:

What are the differences between Revert in Git in Visual Studio 2019 and Android Studio 3.5.3?

问题

在Android Studio 3.5.3中,我可以使用"Revert"来放弃我最新提交的所有更改,如图1所示。

我希望在Vs 2019中执行相同的操作,通过单击"Revert"来放弃所有更改,就像在Android Studio中一样。在Visual Studio 2019中也有一个"Revert"命令,但我不知道Vs 2009中的"Revert"执行什么操作,您可以在图2中看到我的意思。

如果我对这个项目进行了一些修改,在我在Vs 2019中执行"Revert"时会出现错误(请参见图3)。

如果我在这个项目中没有做任何更改,那么当我在Vs 2019中执行"Revert"时,将创建一个名为"Revert Test 3"的新记录(请参见图4)。我不知道"Revert Test 3"是什么意思。

英文:

I can use 'Revert' in Andriod Studio to give up all changes from my latest commit in Android Studio 3.5.3 as you can see Image 1.

I hope to do the same operation in Vs 2019 to give up all changes by clicking 'Revert' like in Android Studio. There is a Revert command in Visual Studio 2019 too, but I don't know what operation the Revert in Vs 2009 does, you can see what I mean in Image 2.

If I apply some modifications to this project, an error will occur when I launch Revert in Vs 2019 (see Image 3).

If I don't do any changes in this project, a new record named 'Revert Test 3' will be created when I launch Revert in Vs 2019 (see Image 4). I don't know what 'Revert Test 3' means.

Image 1

Git在Visual Studio 2019和Android Studio 3.5.3中的”Revert”之间有什么区别?

Image 2
Git在Visual Studio 2019和Android Studio 3.5.3中的”Revert”之间有什么区别?

Image 3
Git在Visual Studio 2019和Android Studio 3.5.3中的”Revert”之间有什么区别?

Image 4
Git在Visual Studio 2019和Android Studio 3.5.3中的”Revert”之间有什么区别?

答案1

得分: 12

这只是不准确的术语。

Android Studio的“还原”并不执行“Git还原”,而是执行“Git重置”。这会丢弃自上次提交以来未提交的更改。

而Visual Studio实际上执行还原操作,也就是创建一个新的提交,其中包含了最新提交的更改被撤销的内容。

另请参阅https://stackoverflow.com/questions/8358035/whats-the-difference-between-git-revert-checkout-and-reset。

英文:

That's just poor terminology.

Android Studio's "revert" does not do a "Git Revert", it does a "Git Reset". This discards your uncommitted changes since the last commit.

Visual Studio actually does a revert, that is, make a new commit in which the changes of the latest commit are turned back.

See also https://stackoverflow.com/questions/8358035/whats-the-difference-between-git-revert-checkout-and-reset.

答案2

得分: 1

"Revert "Test 3"" 将为您创建一个提交,将您在Test 3提交中所做的所有更改还原。

例如,您有一个提交,在该提交中,您将某个方法的访问权限从public更改为private。如果您查看该提交的代码更改,您将看到您已经从public更改为private。
然后,当您执行还原操作时,新的提交(还原 "test 3")将具有更改方法从Private更改为Public的代码更改。

如果您想要还原不是最新提交的提交,这尤其有用。

在图像2中出现错误的原因是因为您在代码中有未暂存的更改时无法还原提交。

我不确定Android Studio中的还原功能如何工作,但如果它按照您的解释运行,Visual Studio的还原和Android Studio的还原是相同的。不同的Git扩展工具会以不同的方式处理操作。

Android Studio
提交1
提交2

还原提交2将使代码的状态与提交1相同。

Visual Studio
提交1
提交2

还原提交2将创建一个新的提交 "Revert "Commit 2"",但最新提交中的代码状态仍将与提交1中的相同。

英文:

"Revert "Test 3"" will create a commit for you reverting all the changes you made in Test 3 commit.

For example, you have a commit where you changed public to private in some method. If you look at the code change of that commit you will se that you changed from public to private.
Then when you are doing a revert, the new commit (revert "test 3") will have code changes changing the method from Private to Public instead.

This is specially good if you wanna revert a commit that is not the latest commit.

The reason you are getting an error in image 2 is because you can't revert a commit when you have unstaged changes in the code.

I am not sure about the revert function in Android studio, but if it work as you explain, both the Visual stuido revert and Android studio Revert is the same. Different Extension tools for git will handle operations differently.

Android studio
Commit 1
Commit 2

Reverting Commit 2 will make the state of the code as in Commit 1.

Visual studio
Commit 1
Commit 2

Reverting Commit 2 will create a new commit "Revert "Commit 2"" but the state of the code in the latest commit will still be as it was in Commit 1.

答案3

得分: -1

我遇到了相同的问题,然后我尝试使用几个其他命令来模拟 git revert 命令:

git fetch origin <LastCommitId>

git reset --hard FETCH_HEAD

执行这些命令,然后你的 vscode 一定会将代码还原到之前的版本。

英文:

I encountered the same issue, then i tried to simulate git revert command using couple of other commands

git fetch origin &lt;LastCommitId&gt;

git reset --hard FETCH_HEAD

execute these commands, then your vscode will definitely revert backs the code to the previous version.

huangapple
  • 本文由 发表于 2020年1月6日 19:38:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/59611461.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定