Search code examples
gitvisual-studioteam-explorer

How can I undo Staged Changes in VS, without overwriting file changes in the Changes set?


I have a Visual Studio project that uses git. In the Team Explore>Changes window, I have a series of changes in the "Staged Changes" region. The problem is that these old, staged changes are no longer compatible with the work that is done in the "Changes" area.

from the "Staged Changes" area, Visual Studio only gives me an option to Unstage, which will merge the Staged Changes into the other change set. However, this isn't what I want to do.

How can I throw out all of the Staged Changes but keep all of the Changes, before I commit? Alternatively, how can I commit just the changes in the "Changes" set, without commiting what's in staging? If I can do that, I can delete what's in staging after my commit.


Solution

  • The Changes page behavior when unstaging a staged change to a file depends on whether the file also has workdir-only changes to it.

    If a file has only staged changes, unstaging it will remove those changes from the index but leave the file with the content in the workdir version. You can then select that same file and undo the workdir changes to get back to the last committed version of the file content.

    If a file has both staged and workdir changes, unstaging the file will discard the index (staged) version and just keep the workdir version of the file.

    Hope this helps.