在新选项卡中打开链接
  1. Copilot 答案
    Undo changes in your Git repo - Azure Repos | Micros…

    Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019 | TFS 2018

    Visual Studio 2019 | Visual Studio 2022

    When you want to undo changes in a Git repo, first decide what type of changes you want to undo. For example, you might want to:

    Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019 | TFS 2018

    Visual Studio 2019 | Visual Studio 2022

    When you want to undo changes in a Git repo, first decide what type of changes you want to undo. For example, you might want to:

    •Discard uncommitted changes to a file by reverting the file to its last committed version. You can also revert a file to any committed version.

    •Revert a branch to a prior state by resetting it to a previous commit.

    •Undo the changes made by a shared commit by creating a new commit that reverses the changes. Because this approach won't rewrite existing commit history, it's suitable for reversing changes made by commits that were pushed and are in use by others.

    •Amend your last commit to modify its content or message. For more information, see How to update your last commit.

    Microsoft Learn

    If you've made changes to a file but haven't committed those changes, you can use Git checkout to quickly discard the changes and revert the file to its last committed version.

    Git checkout can also revert a file to any committed version, when you specify the commit ID.

    Warning

    If there's a chance you might want to reapply the changes that Git checkout would discard, consider stashing those changes instead.

    •Visual Studio 2022

    •Visual Studio 2019 - Git menu

    •Visual Studio 2019 - Team Explorer

    •Git Command Line

    Visual …

    继续阅读

    You can revert a branch to a prior state by using Git reset to reset the branch to a previous commit. Git reset affects all files in all branch folders.

    Git reset has a few options. The default option is to revert the branch to a previous commit, but retain all the subsequent changes as uncommitted changes. Another option is to revert a branch to a previous commit by discarding all changes to all branch files since that commit.

    Warning

    Don't reset a branch to a commit prior to the last commit if the last commit has been pushed and shared with others. Doing so will result in your local branch history no longer matching the remote branch history. For shared branches, see Undo the changes made by a shared commit.

    •Visual Studio 2022

    •Visual Studio 2019 - Git menu

    •Visual Studio 2019 - Team Explorer

    继续阅读

    You can undo the changes made by a commit by using Git revert to create a new commit that reverses those changes. Git revert doesn't delete the original commit. This approach is suitable for undoing the changes made by a shared commit because Git revert won't alter the previous commit history, and so local and remote branch histories continue to match.

    •Visual Studio 2022

    •Visual Studio 2019 - Git menu

    •Visual Studio 2019 - Team Explorer

    •Git Command Line

    1.From the menu bar, choose Git > View Branch History to open the History tab for the current branch.

    2.In the History tab for the current branch, right-click the commit you want to revert and choose Revert to create a new commit that undoes the changes made by the selected commit.

    继续阅读

    •New to Git repos? Learn more

    •Save your work with commits

    继续阅读
  1. 某些结果已被删除